private void UpdateBestCost ( MAM_AgentState currentNode ) { Move move = new Move(currentNode.lastMove); OGAM_Run low_level = new OGAM_Run(this.GetProblemInstance(), move); long nodeCost = low_level.solve(this.costFunction); //Console.WriteLine(low_level.getPlan(false)); if (nodeCost == -1) { throw new TimeoutException("OGAM timeout"); } if (nodeCost < this.getBestCost()) { if (costFunction == CostFunction.SOC) { this.bestSOCCost = (int)nodeCost; } if (costFunction == CostFunction.MakeSpan) { this.bestMakeSpanCost = (int)nodeCost; } this.bestCostLocation = currentNode.lastMove; this.solution = low_level; } }
public bool Solve() { int currentCost = -1; while (!isEmpty()) { // Check if max time has been exceeded if (runner.ElapsedMilliseconds() > Constants.MAX_TIME) { this.totalCost = Constants.TIMEOUT_COST; this.solution = null; Console.WriteLine("Out of time"); this.Clear(); // Total search time exceeded - we're not going to resume this search. return(false); } var currentNode = removeFromOpen(); // Expand bool expanded = Expand(currentNode); nodesExpanded++; if (currentNode.f >= getBestCost() || isEmpty()) // Goal test { success = true; this.Clear(); // Goal found - we're not going to resume this search return(true); } } this.totalCost = Constants.NO_SOLUTION_COST; this.Clear(); // unsolvable problem - we're not going to resume it return(false); }
/// <summary> /// /// </summary> /// <param name="problemInstance"></param> /// <param name="minDepth"></param> /// <param name="runner"></param> /// <param name="minCost">Not taken into account</param> public virtual void Setup ( ProblemInstance problemInstance, int minDepth, CFMAM_Run runner, int minCost = -1, HashSet <MMStarConstraint> constraints = null ) { this.instance = problemInstance; this.runner = runner; this.ClearPrivateStatistics(); this.totalCost = 0; this.solutionDepth = -1; this.milliCap = int.MaxValue; this.goalLocation = null; this.solution = null; this.bestMakeSpanCost = int.MaxValue; this.bestSOCCost = int.MaxValue; this.bestCostLocation = null; this.meetFlag = false; this.success = false; this.openList = new CFMAM_OpenList(this); if (constraints != null) { this.constraints = constraints; } else { this.constraints = new HashSet <MMStarConstraint>(); } // caculate lowest centrality MAM_AgentState agent = getLowestCentralityAgent(); CalculateH(agent, null); CalculateF(agent); closed(agent); openList.Add(agent); }