Beispiel #1
0
        public bool inform(Agent a, bool USE_OTHER_MODEL)
        {
            //Check if we already met this guy
            if (!concepts.ContainsKey(a.Name))
            {
                concepts[a.Name] = new Agent(a.Name);
            }

            //Randomize our beliefs
            Random rnd = new Random();
            IEnumerable <Relation> shuffledBeliefs = beliefs.OrderBy((r) => { return(rnd.Next()); });

            //Tell him something
            Agent            interlocutor = concepts[a.Name] as Agent;
            RelationComparer rComp        = new RelationComparer();

            foreach (Relation r in shuffledBeliefs)
            {
                if (USE_OTHER_MODEL)
                {
                    if (!interlocutor.beliefs.Contains(r, rComp))
                    {
                        //We can say something that he doesn't know
                        Console.WriteLine(this.Name + " think & says to " + interlocutor.Name + " : " + r.asSentence());
                        a.considerInformation(r, new List <Agent>(), this);
                        //We consider that now he knows
                        updateOtherRepresentation(interlocutor.Name, r);
                        return(true);
                    }
                }
                else
                {
                    Console.WriteLine(this.Name + " says to " + interlocutor.Name + " : " + r.asSentence());
                    a.considerInformation(r, new List <Agent>(), this);
                    //We consider that now he knows
                    updateOtherRepresentation(interlocutor.Name, r);
                    return(true);
                }
            }

            //Nothing to say
            Console.WriteLine(this.Name + " think & and has nothing to say to " + interlocutor.Name);
            return(false);
        }
Beispiel #2
0
        public bool inform(IEnumerable <Agent> group, bool USE_OTHER_MODEL)
        {
            //Check if we already met this guy
            foreach (Agent a in group)
            {
                if (!concepts.ContainsKey(a.Name))
                {
                    concepts[a.Name] = new Agent(a.Name);
                }
            }

            //Rank our beliefs according to how rarely they are spread around
            RelationComparer           rComp         = new RelationComparer();
            Random                     rnd           = new Random();
            Dictionary <Relation, int> rankedBeliefs = new  Dictionary <Relation, int>();
            Relation                   bestRelation  = null;

            foreach (Relation r in beliefs)
            {
                rankedBeliefs[r] = 0;

                if (USE_OTHER_MODEL)
                {
                    foreach (Agent a in group)
                    {
                        Agent otherRepresentation = concepts[a.Name] as Agent;
                        if (!otherRepresentation.beliefs.Contains(r, rComp))
                        {
                            rankedBeliefs[r]++;
                        }
                    }
                }
                else
                {
                    rankedBeliefs[r] = rnd.Next();
                }

                if (bestRelation == null || rankedBeliefs[bestRelation] < rankedBeliefs[r])
                {
                    bestRelation = r;
                }
            }


            //Tell the relation that is the less know
            if (rankedBeliefs[bestRelation] != 0)
            {
                //Console.WriteLine(this.Name + " hope to inform " + rankedBeliefs[bestRelation] + " agents by saying " + bestRelation.asSentence());
                int reallyInformed = 0;
                foreach (Agent a in group)
                {
                    Agent otherRepresentation = concepts[a.Name] as Agent;
                    //We can say something that he doesn't know
                    if (a.considerInformation(bestRelation, group, this))
                    {
                        reallyInformed++;
                    }

                    //We consider that now he knows
                    updateOtherRepresentation(otherRepresentation.Name, bestRelation);
                }
                //Console.WriteLine(this.Name + "really informed " + reallyInformed + " agents");
            }
            else
            {
                //Nothing to say
                //Console.WriteLine(this.Name + " think & and has nothing to say");
            }
            return(false);
        }