コード例 #1
0
        public long solve(CFMAStar.CostFunction costFunction)
        {
            // Independence Detection
            List <List <TimedMove> > nonConflictsPaths = null;
            IndependentDetection     id = new IndependentDetection(this.problemInstance, this.goalState);

            MAM_AgentState[] newStartPositions = id.Detect(out nonConflictsPaths);
            if (newStartPositions.Length != 0)
            {
                this.problemInstance = problemInstance.ReplanProblem(newStartPositions);
                this.reducer         = new CFMAM_MCMF_Reducer(this.problemInstance, this.goalState);
                reducer.reduce(costFunction);
                if (reducer.outputProblem == null)
                {
                    return(-1);
                }
                MinCostMaxFlow mcmfSolver = new MinCostMaxFlow(reducer.outputProblem);
                timer    = Stopwatch.StartNew();
                solution = mcmfSolver.SolveMinCostFlow();
                List <TimedMove>[] partialPlan = this.reducer.GetCFMAMSolution(this.solution, this.mcmfTime, true);
                if (costFunction == CFMAStar.CostFunction.MakeSpan)
                {
                    while (!isPathForEachAgent(partialPlan))
                    {
                        this.reducer.addNetworkLayer();
                        mcmfSolver  = new MinCostMaxFlow(reducer.outputProblem);
                        solution    = mcmfSolver.SolveMinCostFlow();
                        partialPlan = this.reducer.GetCFMAMSolution(this.solution, this.mcmfTime, true);
                    }
                }
                timer.Stop();
                this.plan         = mergePlans(partialPlan, nonConflictsPaths);
                this.mcmfTime     = timer.ElapsedMilliseconds;
                this.solutionCost = calculateCost(this.plan, costFunction);
            }
            else
            {
                this.plan         = nonConflictsPaths;
                this.solutionCost = calculateCost(this.plan, costFunction);
            }

            return(this.solutionCost);
        }