function convertStringPrologPlansToGraphs($prologPlans) { //Clean plan for regular expressions processing $plans = prologPlanCollection::preparePlans($prologPlans); //Generate an array of all plans and their timepoints $plansAndTemporalOrderings = prologPlanCollection::organisePlans($plans); //Convert plans and ordering into a directed graphs $plansAndTemporalOrderingsSize = sizeof($plansAndTemporalOrderings); for ($index = 0; $index < $plansAndTemporalOrderingsSize; $index++) { $orderingCollection = $plansAndTemporalOrderings[$index]['ordering']; $planCollection = $plansAndTemporalOrderings[$index]['plan']; $planGraphList[$index] = graphPlan::convertToGraphPlan($orderingCollection, $planCollection); flush(); } return $planGraphList; }
/** * @return graphPlan * @param $orderingCollection OrderingCollection * @param $planCollection PlanCollection * @desc Creates a graphplan from the orderings and plan actions */ function convertToGraphPlan($orderingCollection, $planCollection) { $planGraph = new graphPlan(); //The start node will always be the first node //Otherwise the plans would be undeterministic $startnode = $planCollection->startNode(); //There will be a node for every timepoint $nodeList = $orderingCollection->findallTimepoints(); //Find all edges $edgeList = $orderingCollection->findallEdges(); //Create Nodes $planGraph->populateNodes($nodeList, $planCollection); //Create Edges $planGraph->createEdges($edgeList); //Set the start Node $planGraph->setStartNode($startnode->getTimePoint()); return $planGraph; }