function actOnJavascriptPlanActions($actionPackets) { $plansConvergence = false; $constraintsArray = array(); //Setup the javascript collections for ($index = 0; $index < sizeof($actionPackets); $index++) { $constraintsArray[$index] = new javaScriptCollection(); } while (!$plansConvergence) { //Plans have have converged to a single plan $actionArray = array(); $packetCollection = array(); for ($index = 0; $index < sizeof($actionPackets); $index++) { $actionNode = $actionPackets[$index]->getAction(); $data = $actionNode->getData(); $actionPredicate = node::getNodeData($data); //Find the values for this conditional action $predicateValues = $actionPredicate->getPredicateValues(); //Create a new javascript constraint $javaScriptConstraint = new javaScriptConstraint($predicateValues[1]->toString(), $predicateValues[2]->toString(), $predicateValues); //Add this constraint to the associated collection $constraintsArray[$index]->addConstraint($javaScriptConstraint); //Find the next action for this action packet $nextActionPackets = planAction::fetchNextAction($actionPackets[$index]->getPlans()); $nextAction = $nextActionPackets[1]; $actionArray[$index] = $nextAction[0]->toString(); $packetCollection = array_merge($packetCollection, $nextActionPackets[0]); } $plansConvergence = arrays::allEqual($actionArray); if (!$plansConvergence) { $actionPackets = $packetCollection; } } //Plans must have convereged so it does not matter which one we return! return array('actionPackets' => $actionPackets[0], 'constraints' => $constraintsArray); //return $actionPackets[0]; }
//Retreive whether the edge progression test was passed $edgeProgressionResult = $edgeProgressionPacket['match']; //Retrive the selected action packet $selectedActionPacket = $edgeProgressionPacket['actionPacket']; if ($edgeProgressionResult) { //The edgeprogression test succeded //Check the chosen action packet if ($selectedActionPacket->atGoal()) { //At goal node $goal = true; planArchieving::archive($_POST['workflowID']); systemMessages::message("Goal node reached!"); } else { //Only one action packet should be returned $plans = $selectedActionPacket->getPlans(); $newPlannerProgress = planAction::fetchNextAction($plans); $action = node::getNodeData($newPlannerProgress[1]); if ($action->getPredicateName() != 'edgeProgression') { $match = true; } else { } $plannerProgress = $newPlannerProgress; $newPlannerProgress = array(); } } } debug::message("edge progression test :" . $edgeProgressionResult); if ($edgeProgressionResult) { if (!$goal) { //No point in updating plans if we have reached the goal planningAgent::updatePlans($plans);
function actOnPlan($planGraphList, $action) { $match = false; $result = array(); $actionList = array(); while (!$match) { //Find me all actions up untill and including submission $plannerProgress = planAction::findRequiredActions($planGraphList, $action); //Reason for the planner stopping switch ($plannerProgress['reason']) { case 'conditional': $result = planAction::conditionBehaviour($plannerProgress); $actionList = $result['actionList']; $planGraphList = $result['plans']->getPlans(); $plannerProgress['actionPackets'] = $result['plans']; break; case 'match': $actionList = array_merge($actionList, $plannerProgress['actionNames']); $match = true; break; case 'goal': $match = true; break; } } if (isset($result['javaConstraints'])) { return array('actionPackets' => $plannerProgress['actionPackets'], 'actionList' => $actionList, 'javaConstraints' => $result['javaConstraints']); } else { return array('actionPackets' => $plannerProgress['actionPackets'], 'actionList' => $actionList, 'javaConstraints' => array()); } }
} } } function findDatabaseActions($actionList) { $result = array(); for ($index = 0; $index < sizeof($actionList); $index++) { if ($actionList[$index]->getPredicateName() == 'databaseFetch') { array_push($result, $actionList[$index]); } } return $result; } //Fetch the plan list $planGraphList = graphPlanDatabaseAccess::getPlanGraphList($_GET['workflowID']); $result = planAction::actOnPlan($planGraphList, "formSubmission"); //Seperate the action list from the graph plans $actionList = $result['actionList']; $javaConstraints = $result['javaConstraints']; //Convert constraints plans into Javascript arrays $planString = "\nvar planCollection = Array();\n"; for ($index = 0; $index < sizeof($javaConstraints); $index++) { $planString .= $javaConstraints[$index]->toJavascriptArray($index); } //Find all javaScript predicates and use order to dictate user entry $javaScriptPredicates = javaScript::findJavaScriptActions($actionList); $prologTimeLine = javaScript::javascriptArray($javaScriptPredicates); //Begin JAVAscript controls ?>