func (ml *MultilevelLandscape) Init(arg goabm.Modeler) {
	/* ml.PhysToVirtual = make(map[goabm.AgentID]goabm.AgentID)
	   ml.VirtualToPhys = make(map[goabm.AgentID]goabm.AgentID)
	*/
	ml.Base.Init(arg)

	for i, agent := range *ml.Base.GetAgents() {
		a := agent.(*EchoChamberAgent)

		a.OfflineChangeCounter = 0
		a.OnlineChangeCounter = 0
		a.VAgent.ID = a.PAgent.(*goabm.FLWMAgent).Seqnr +
			goabm.AgentID(ml.Base.(*goabm.FixedLandscapeWithMovement).NAgents)
		(*ml.Overlay.GetAgents())[i] = a
		ml.Overlay.(*goabm.NetworkLandscape).SetAgent(i, a.VAgent)

		//agenter.(*goabm.FLWMAgent).Seqnr + goabm.AgentID(m.Landscape.Base.(*goabm.FixedLandscapeWithMovement).NAgents)
	}
	/*	// create a lookup table, so that every agent has a node in each world
		for i, agent := range ml.Base.GetAgents() {
		a := agent.(*EchoChamberAgent)
		 newId := a.Seqnr + ml.Base.NAgents
		 PhysToVirtual[a.Seqnr] = newID
		 VirtualToPhys[newID] = a       .Seqnr
		}*/
}
Exemplo n.º 2
0
func (e *EchoChamberModel) GoogleBlog(f Feature) *Blog {
	// we google a blog for our cultural identity (features)
	// rank all blogs for similarity (last post), return the best

	ranking := make(map[goabm.AgentID]float64, len(e.Blogger))

	for i, blog := range e.Blogger {

		lastPost := blog.Posts[len(blog.Posts)-1]
		sim := Similarity(f, lastPost.Message)
		ranking[i] = sim
	}

	// find best match
	best := goabm.AgentID(0)
	for i, rank := range ranking {
		if rank > ranking[best] {
			best = i
		}
	}
	bestBlog := e.Blogger[best]
	return bestBlog
}
// required for the simulation interface, called everytime when the agent is activated
func (a *EchoChamberAgent) Act() {

	var OtherIsOnline bool
	//fmt.Printf("agent (%d - %d)\n",a.PAgent.(*goabm.FLWMAgent).Seqnr,a.VAgent.ID)
	var other *EchoChamberAgent
	// step 1: decide in which world we interact
	dicew := rand.Float64()
	if dicew <= a.Model.POnline {

		// we are in the virtual world
		// 2.v.1 in vw decide whether looking for blogs
		// 2.v.2 select a blog & change traits
		diceb := rand.Float64()
		if diceb <= a.Model.PLookingForBlogs {
			// first ditch all existing connections
			a.VAgent.ClearLinks()
			// find at most n(FollowedBlogs) most matching blogs
			// v1 exponentional exhaustive search, check every other agent
			similarities := make(map[float64]goabm.GenericAgent)
			var keys []float64
			for _, pa := range *a.Model.Landscape.Overlay.GetAgents() {
				potentialAgent := pa.(*EchoChamberAgent)
				if potentialAgent.VAgent.ID != a.VAgent.ID { // no comparing with ourselve
					sim := a.Similarity(potentialAgent)
					similarities[sim] = potentialAgent.VAgent

				}
				//fmt.Println("nort: ", a.VAgent.ID, potentialAgent.VAgent.ID)
			} //(*goabm.NetworkLandscape).

			// sort the other agents according to similarities
			for k := range similarities {
				keys = append(keys, k)
			}
			// highes P first
			sort.Sort(sort.Reverse(sort.Float64Slice(keys)))

			// pick FollowedBlogs and connect in the virtual space

			for i := 0; i < a.Model.FollowedBlogs && i < len(keys); i++ {
				k := keys[i]
				blog := similarities[k]
				// fmt.Printf("%f\t",k)
				a.VAgent.ConnectTo(&blog)
			}

		}

		// select a blog random blog
		// chance to interact is its similarity
		randomLink := a.VAgent.GetRandomLink()
		if randomLink == nil {
			// there is no link at all might want to look for blogs next time??
			return
		}

		other = a.Model.Landscape.Overlay.GetAgentById(randomLink.ID + 0*goabm.AgentID(a.Model.Landscape.Base.(*goabm.FixedLandscapeWithMovement).NAgents)).(*EchoChamberAgent)
		//sim := a.Similarity(other)
		//fmt.Printf("sim virtual: %f\n", sim)
		/*if other == nil {

		}*/
		OtherIsOnline = true
		//other = a.VAgent.GetRandomNeighbor().(*EchoChamberAgent)
	} else {
		OtherIsOnline = false
		// offline world
		// 2.p.1 in pw execute agent logic from axelrods culture model

		dicem := rand.Float64()
		// (i) agent decides to move according to the probability veloc
		if dicem <= a.Model.PVeloc {
			a.PAgent.MoveRandomly(a.Model.Steplength)
			//fmt.Println("move...")
		}

		neighbor := a.PAgent.GetRandomNeighbor()

		if neighbor == nil {
			// there is no agent around to interace :( maybe move a bit?
			return
		} else {
			other = neighbor.(*EchoChamberAgent)
		}
	}

	// (ii) (a) selects a neighbor for cultural interaction
	sim := a.Similarity(other)
	if sim >= 0.99 {
		// agents are already equal
		return
	}
	dice := rand.Float64()
	//interact with sim% chance
	if dice <= sim {
		for i := range a.Features {
			if a.Features[i] != other.Features[i] {
				//fmt.Printf("%d influenced %d\n", other.seqnr, a.seqnr)
				a.Features[i] = other.Features[i]
				if OtherIsOnline {
					a.OnlineChangeCounter++
				} else {
					a.OfflineChangeCounter++
				}
				return
			}

		}
	}

}