public SpaceData(ExplorationSpace space) { IList<ExplorationNode> nodes = space.Nodes; Dictionary<ExplorationEdge, uint> edgeToId; this.Edges = EncodeEdges(nodes, out edgeToId).ToArray(); this.Nodes = EncodeNodes(nodes, edgeToId).ToArray(); }
public static string Run(ExplorationSpace space) { string allStories = ""; foreach (var scorer in GoalSelector.Scorers) { allStories += "#" + scorer.Method.Name + "\n"; IEnumerable<Candidate> candidates = GoalSelector.GetCandidates( space, space.Nodes[0], scorer); foreach (Candidate candidate in candidates) allStories += FormatStory(candidate) + "%\n"; } return allStories; }
public IEnumerable Explore(WorldState initial, EventDescriptor[] evtDescs) { List<ExplorationNode> stateSpace = new List<ExplorationNode>(); this.status = ExplorationStatus.Exploring; foreach (var step in Step_Exploring(initial, evtDescs, stateSpace)) { exploredNodes = stateSpace.Count; if (exploredNodes > MAX_NODES) break; yield return null; } // TODO: Temporarily disabling expanding.. //this.status = Status.Expanding; //foreach (var step in Step_Expanding(stateSpace)) // yield return null; this.status = ExplorationStatus.PageRank; foreach (var step in Step_PageRanking(stateSpace, 0.85, 200, 5, 0.01)) yield return null; this.status = ExplorationStatus.InversePageRank; foreach (var step in Step_InversePageRanking(stateSpace, 0.85, 200, 5, 0.01)) yield return null; this.status = ExplorationStatus.Path; #if !GPU foreach (var step in Step_Pathing(stateSpace)) yield return null; #else Console.WriteLine("\nProcessing paths on GPU..."); Crunch.GPUGraphUtil.GPUPath(stateSpace); #endif //this.status = ExplorationStatus.MinCut; //foreach (var step in Step_MinCut(stateSpace)) // yield return null; this.status = ExplorationStatus.Done; this.space = new ExplorationSpace(stateSpace); yield break; }
public SpaceExplorer() { this.status = ExplorationStatus.Initializing; this.space = null; }
public static IEnumerable<Candidate> GetCandidates( ExplorationSpace space, ExplorationNode start, ExplorationNode lastGoal, HashSet<uint> busyObjects, Scorer scorer, int numRecommendations, bool descending) { if (busyObjects == null) busyObjects = new HashSet<uint>(); List<Candidate> candidates = new List<Candidate>(); foreach (ExplorationNode node in space.Nodes) { if (start == node) continue; // Make sure it's reachable ExplorationEdge[] path = start.GetPathOut(node.Id); if (path != null) { // Add it as a candidate if the score is high enough double score = scorer(start, node); ExplorationEdge edge = path[0]; ExplorationNode goal = path.Last().Target; double sentimentScore = SentimentScore(score, path); candidates.Add(new Candidate(path, goal, sentimentScore)); } } // Sort the candidates by score candidates.Sort((c1, c2) => c1.Score.CompareTo(c2.Score)); if (descending == true) candidates.Reverse(); // Add the previous goal to the front if we still have a path to it if (lastGoal != null) { ExplorationEdge[] oldPath = start.GetPathOut(lastGoal.Id); if (oldPath != null) candidates.Insert(0, new Candidate(oldPath, lastGoal, 0.0)); } HashSet<ExplorationNode> seenGoals = new HashSet<ExplorationNode>(); HashSet<ExplorationEdge> seenEdges = new HashSet<ExplorationEdge>(); // Pick the top N int count = 0; foreach (Candidate candidate in candidates) { ExplorationNode goal = candidate.Goal; if (candidate.Path.Length == 0) continue; ExplorationEdge edge = candidate.Path[0]; // Nix this event if it uses an object that's currently in use // TODO: Assumes only one event per edge TransitionEvent evt = edge.Events[0]; foreach (uint id in evt.Participants) if (busyObjects.Contains(id) == true) goto skipCandidate; // If this is a novel direction to go, add it bool seenGoal = seenGoals.Contains(goal); bool seenEdge = seenEdges.Contains(edge); if (seenGoal == false && seenEdge == false) { seenGoals.Add(goal); seenEdges.Add(edge); count++; yield return candidate; } if (count >= numRecommendations) break; skipCandidate : continue; } }
public static IEnumerable<Candidate> GetCandidates( ExplorationSpace space, ExplorationNode start, int numRecommendations) { return GetCandidates( space, start, null, null, DEFAULT_SCORER, numRecommendations, DEFAULT_DESCENDING); }
public static IEnumerable<Candidate> GetCandidates( ExplorationSpace space, ExplorationNode start, Scorer scorer) { return GetCandidates( space, start, null, null, scorer, DEFAULT_RECOMMENDATIONS, DEFAULT_DESCENDING); }
public static IEnumerable<Candidate> GetCandidates( ExplorationSpace space, ExplorationNode start, ExplorationNode lastGoal, HashSet<uint> busyObjects) { return GetCandidates( space, start, lastGoal, busyObjects, DEFAULT_SCORER, DEFAULT_RECOMMENDATIONS, DEFAULT_DESCENDING); }
public Recommender(ExplorationSpace space) { this.space = space; this.current = space.Nodes[0]; this.busyObjects = new HashSet<uint>(); }