/// <summary>
        /// Tries to find a plan for this group, that will not conflict with the given plan,
        /// and still has the same solution cost as the current solution cost.
        /// This is used in the ImprovedID() method.
        /// </summary>
        /// <param name="plan"></param>
        /// <param name="runner"></param>
        /// <returns></returns>
        public bool ReplanUnderConstraints(Plan plan, Run runner)
        {
            int  oldCost = this.solutionCost;
            Plan oldPlan = this.plan;
            HashSet <TimedMove> reserved = new HashSet <TimedMove>();

            plan.AddPlanToHashSet(reserved, Math.Max(plan.GetSize(), this.plan.GetSize()) - 1); // TODO: Why -1?

            this.instance.parameters[IndependenceDetection.ILLEGAL_MOVES_KEY] = reserved;
            this.instance.parameters[IndependenceDetection.MAXIMUM_COST_KEY]  = solutionCost;
            bool success = this.Solve(runner);

            this.instance.parameters.Remove(IndependenceDetection.ILLEGAL_MOVES_KEY);
            this.instance.parameters.Remove(IndependenceDetection.MAXIMUM_COST_KEY);
            if (success == false)
            {
                this.solutionCost = oldCost;
                this.plan         = oldPlan;
            }
            return(success);
        }
Beispiel #2
0
        /// <summary>
        /// Tries to find a plan for this group, that will not conflict with the given plan,
        /// and still has the same solution cost as the current solution cost.
        /// This is used in the IndependenceDetection() method.
        /// </summary>
        /// <param name="plan"></param>
        /// <param name="runner"></param>
        /// <returns></returns>
        public bool ReplanUnderConstraints(Plan plan, Run runner)
        {
            bool                success;
            int                 oldCost     = this.solutionCost;
            WorldState          oldSolution = this.solution;
            Plan                oldPlan     = this.plan;
            HashSet <TimedMove> reserved    = new HashSet <TimedMove>();

            plan.AddPlanToHashSet(reserved, Math.Max(plan.GetSize(), this.plan.GetSize()) - 1);

            this.instance.parameters[Trevor.ILLEGAL_MOVES_KEY] = reserved;
            this.instance.parameters[Trevor.MAXIMUM_COST_KEY]  = solutionCost;
            success = this.Solve(runner);
            this.instance.parameters.Remove(Trevor.ILLEGAL_MOVES_KEY);
            this.instance.parameters.Remove(Trevor.MAXIMUM_COST_KEY);
            if (success == false)
            {
                this.solutionCost = oldCost;
                this.solution     = oldSolution;
                this.plan         = oldPlan;
            }
            return(success);
        }