// Converts the Cytoscape nodes into animation nodes and pushes them onto the list that tracks frontiers // We have to clone the frontier and then delete the elements from the copy because there is no way // to iterate through the frontier ordered by priority. private static void storeFrontierOverTime(AStarSpecificAnimation frontierOverTime, IntervalHeap <CytoscapeNode> frontier) { IntervalHeap <CytoscapeNode> frontierCopy = cloneFrontier(frontier); AStarAnimationNode animationNode; List <AStarAnimationNode> currentFrontier = new List <AStarAnimationNode>(); CytoscapeNode cyNode; while (frontierCopy.Any()) { cyNode = frontierCopy.DeleteMax(); animationNode = new AStarAnimationNode(cyNode.id); animationNode.name = cyNode.name; animationNode.f = cyNode.f; currentFrontier.Add(animationNode); } frontierOverTime.frontierOverTime.Add(currentFrontier); }
/* * Currently using two different classes to perform simulations. One is prefaced with * Cytoscape, which is passed in via the UI's ajax call and used in the simulation. * The other is prefaced with Animation, which is a simplified form and is * passed back to the UI to animate. In addition to it being a simplified form, it * also does not contain any circular references, unlike the Cytoscape versions. * C# has issues serializing objects with circular references, unlike Javascript. */ public static Animation runSimulation(int startID, int goalID, CytoscapeParams cyParams) { //return testAnim(startID, goalID); Animation results = new Animation(); AStarSpecificAnimation aStarSpecific = new AStarSpecificAnimation(); aStarSpecific.frontierOverTime = new List <List <AStarAnimationNode> >(); List <AnimationFrame> frames = new List <AnimationFrame>(); bool goalFound = false; CytoscapeMap map = new CytoscapeMap(initializeInternalNodes(cyParams.nodes)); IntervalHeap <CytoscapeNode> frontier = new IntervalHeap <CytoscapeNode>(); CytoscapeNode current = map.getNode(startID); while (!goalFound) { //Add new frontier to priority queue addToFrontier(map, frontier, current); //Store path every iteration for animation trackAnimationFrame(frames, current); //Store the frontier every iteration for animation storeFrontierOverTime(aStarSpecific, frontier); //Get the next node to expand current = frontier.DeleteMax(); //When done we record the last frame's information and break if (current.id == goalID) { goalFound = true; trackAnimationFrame(frames, current); storeFrontierOverTime(aStarSpecific, frontier); } } results.frames = frames; results.simulationSpecific = aStarSpecific; return(results); }