Ejemplo n.º 1
0
 public Candidate(
     ExplorationEdge edge,
     ExplorationNode goal,
     double score)
 {
     this.Goal = goal;
     this.Edge = edge;
     this.Score = score;
 }
Ejemplo n.º 2
0
 public Candidate(
     ExplorationEdge[] path,
     ExplorationNode goal,
     double score)
 {
     this.Goal = goal;
     this.Path = path;
     this.Score = score;
 }
Ejemplo n.º 3
0
    public IEdge Clone()
    {
        ExplorationEdge newEdge =
            new ExplorationEdge(
                this.Source,
                this.Target,
                this.Events);

#if !PARALLEL
        newEdge.Saturated = this.Saturated;
#endif
        return newEdge;
    }
Ejemplo n.º 4
0
    private static double ScorePath(
        ExplorationEdge[] path)
    {
        double result = 1.0;
        foreach (ExplorationEdge edge in path)
        {
            TransitionEvent evt = edge.Events[0];
            EventSignature sig = 
                EventLibrary.Instance.GetSignature(evt.Descriptor.Name);

            foreach (string sent in sig.Sentiments)
                result += 0.1;
        }
        return result;
    }
Ejemplo n.º 5
0
    public EdgeData(uint id, ExplorationEdge edge)
    {
        this.EdgeId = id;

        this.IdFrom = edge.Source.Id;
        this.IdTo = edge.Target.Id;

        this.EventNames = new string[edge.Events.Length];
        this.EventParticipants = new uint[edge.Events.Length][];
        for (int i = 0; i < edge.Events.Length; i++)
        {
            TransitionEvent evt = edge.Events[i];
            EventNames[i] = evt.Descriptor.Name;
            EventParticipants[i] = evt.Participants;
        }
    }
Ejemplo n.º 6
0
        //Distance(source, dest)
        //Distance(dest, source)
        //Pagerank(source)
        //Pagerank(dest)
        //InvPagerank(source)
        //InvPagerank(dest)
        //MinCut(source, dest)
        //MinCut(dest, source)
        //Avg. MinCutIn(source)
        //Avg. MinCutIn(dest)
        //Avg. MinCutOut(source)
        //Avg. MinCutOut(dest)
        //NumIncoming(source)
        //NumIncoming(dest)
        //NumOutgoing(source)
        //NumOutgoing(dest)

        public static double SentimentScore(double score, ExplorationEdge[] path)
        {
          foreach (ExplorationEdge edge in path)
          {
            EventDescriptor transDesc = edge.Events[0].Descriptor;
            foreach (string sentiment in transDesc.Sentiments)
            {
              if (SentimentWant.Contains(sentiment) == true)
                score *= 100.0;
              if (SentimentDont.Contains(sentiment) == true)
                score *= 0.01;
            }
          }

          return score;
        }
Ejemplo n.º 7
0
    public void OnButtonClick(int which)
    {
        DebugUtil.Assert(this.candidates.Count > which);
        Candidate candidate = this.candidates[which];
        DebugUtil.Assert(candidate != null);

        // TODO: Only taking the first event
        TransitionEvent evt = candidate.Edge.Events[0];
        DebugUtil.Assert(evt != null);

        this.DeselectAll(evt);
        EventSignature sig = (EventSignature)evt.Descriptor;
        SmartEvent instance =
            sig.Create(this.GetParameters(evt));

        string output = evt.Descriptor.Name;
        foreach (object parameter in this.GetParameters(evt))
        {
            SmartObject obj = (SmartObject)parameter;
            output += " " + obj.gameObject.name;
            
        }

        Debug.LogWarning("Executing: " + output);

        instance.StartEvent(1.0f);
        this.previousGoal = candidate.Goal;
        this.Depopulate();

        this.currentEvent = instance;
        this.currentEdge = candidate.Edge;
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Checks the second transition in a 2-transition jump and sees if we can
    /// perform the collapse (there's no overlap, etc.)
    /// </summary>
    /// <param name="beginning">The first expanded node (beginning, middle, 
    /// end)</param>
    /// <param name="jump1">The first edge (beginning-middle)</param>
    /// <param name="jump1Events">The events in the first edge</param>
    /// <param name="involvedInFirst">The objects involved in jump1</param>
    /// <param name="edgesToAdd">(out) A list in which we write the edges to
    /// add to the graph</param>
    private static void AnalyzeEndpoints(
        ExplorationNode beginning,
        ExplorationEdge jump1,
        IEnumerable<TransitionEvent> jump1Events,
        HashSet<uint> involvedInFirst,
        IList<ExplorationEdge> edgesToAdd)
    {
        // Get all of the final endpoint jumps (middle-end)
        foreach (ExplorationEdge jump2 in jump1.Target.Outgoing)
        {
            ExplorationNode end = jump2.Target;
            List<TransitionEvent> jump2Events =
                new List<TransitionEvent>(jump2.Events);

            // All the objects in jump2 
            HashSet<uint> involvedSecond = new HashSet<uint>();
            GetInvolved(jump2Events).ForEach(
                (uint id) =>
                {
                    DebugUtil.Assert(involvedSecond.Contains(id) == false);
                    involvedSecond.Add(id);
                });

            // There's no overlap
            if (involvedInFirst.Overlaps(involvedSecond) == false)
            {
                List<TransitionEvent> combined = new List<TransitionEvent>();
                combined.AddRange(
                    jump1Events.Convert(s => new TransitionEvent(s)));
                combined.AddRange(
                    jump2Events.Convert(s => new TransitionEvent(s)));
                edgesToAdd.Add(
                    new ExplorationEdge(beginning, end, combined.ToArray()));
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Expands all of the transitions and adds the resulting world states
    /// to the list of nodes during exploration
    /// </summary>
    /// <param name="openList">The list of nodes we haven't explored
    /// yet</param>
    /// <param name="seen">The list of nodes we've seen</param>
    /// <param name="curNode">The current node from the open list</param>
    private static void AddExpansionsToLists(
        EventDescriptor[] evtDescs,
        List<ExplorationNode> openList,
        Dictionary<WorldState, ExplorationNode> seen,
        ExplorationNode curNode)
    {
        // Find all of the event signatures
        foreach (EventDescriptor evtDesc in evtDescs)
        {
            IEnumerable<Tuple<WorldState, uint[]>> expansions =
                GetExpansions(curNode.State, evtDesc);

            // Get all of the expansions
            foreach (Tuple<WorldState, uint[]> expansion in expansions)
            {
                WorldState expansionState = expansion.Item1;
                ExplorationNode expansionNode;

                // If we haven't seen the world state
                if (seen.TryGetValue(expansionState, out expansionNode) == false)
                {
                    expansionNode = new ExplorationNode(expansionState);
                    openList.Add(expansionNode);
                    seen.Add(expansionState, expansionNode);
                }

                DebugUtil.Assert(expansionNode != null);

                TransitionEvent transition = new TransitionEvent(evtDesc, expansion.Item2);
                ExplorationEdge edge = new ExplorationEdge(
                    curNode,
                    expansionNode,
                    transition);
                curNode.AddOutgoing(edge);
                expansionNode.AddIncoming(edge);
            }
        }
    }