Example #1
0
        public Belief merge(Belief oldBelief, Belief b)
        {
            if (b.getBeliefType() == Belief.BeliefType.ACTOR)
            {
                // Convert to belief actors
                Belief_Actor oldActorBelief      = (Belief_Actor)oldBelief;
                Belief_Actor incomingActorBelief = (Belief_Actor)b;

                // To keep track of what to merge
                bool incomingBeliefMoreRecent = !incomingActorBelief.getIsAlive() && oldActorBelief.getIsAlive() ||
                                                incomingActorBelief.getBeliefTime() > oldActorBelief.getBeliefTime();

                bool onlyIncomingBeliefIsClassified = oldActorBelief.getAffiliation() == (int)Affiliation.UNCLASSIFIED &&
                                                      incomingActorBelief.getAffiliation() != (int)Affiliation.UNCLASSIFIED;

                bool onlyOldBeliefIsClassified = oldActorBelief.getAffiliation() != (int)Affiliation.UNCLASSIFIED &&
                                                 incomingActorBelief.getAffiliation() == (int)Affiliation.UNCLASSIFIED;

                if (!incomingBeliefMoreRecent && !onlyIncomingBeliefIsClassified)
                {
                    return(oldBelief);
                }
                else if (incomingBeliefMoreRecent && onlyOldBeliefIsClassified)
                {
                    return(mergeActorBeliefs(oldActorBelief, incomingActorBelief));
                }
                else if (!incomingBeliefMoreRecent && onlyIncomingBeliefIsClassified)
                {
                    return(mergeActorBeliefs(incomingActorBelief, oldActorBelief));
                }
                else
                {
                    return(incomingActorBelief);
                }
            } // end actor merge policy
            else
            {
                // General merge policy (take newest belief) for every belief except actor
                if (oldBelief.getBeliefTime() < b.getBeliefTime())
                {
                    return(b);
                }
                else
                {
                    return(oldBelief);
                }
            }
        }
Example #2
0
        // Check if belief is newer than current belief of matching type and id, if so,
        // replace old belief with b.
        public void addBeliefToDataManager(Belief b, int sourceId)
        {
            lock (dataManagerLock)
            {
                SortedDictionary <int, Belief> tempTypeDict = getBeliefsFor(b.getTypeKey());
                if (tempTypeDict != null)
                {
                    Belief oldBelief;
                    if (!getBeliefsFor(b.getTypeKey()).TryGetValue(b.getId(), out oldBelief) || oldBelief.getBeliefTime() < b.getBeliefTime())
                    {
                        getBeliefsFor(b.getTypeKey())[b.getId()] = b;
                    }
                }
                else
                {
                    getBeliefsFor(b.getTypeKey())[b.getId()] = b;
                }

                /*
                 * Do not update actors in this function
                 * SortedDictionary<int, bool> sourceDistanceDictionary;
                 * if (actorDistanceDictionary.TryGetValue(sourceId, out sourceDistanceDictionary))
                 * {
                 *  foreach (KeyValuePair<int, bool> entry in sourceDistanceDictionary)
                 *  {
                 *      SoaActor destActor = soaActorDictionary[entry.Key];
                 *      if (entry.Value)
                 *      {
                 *          destActor.addBelief(b, sourceId);
                 *      }
                 *  }
                 * }*/
            }
        }