Beispiel #1
0
        public void AddSubSetHeuristics()
        {
            MAM_HeuristicCalculator hCalculator = hCalculatorList[0][0];

            hCalculatorList = new List <List <MAM_HeuristicCalculator> >();

            foreach (MAM_AgentState agent in this.instance.m_vAgents)
            {
                agent.numOfAgentsInBestHeuristic = hCalculator.GetNumberOfAgents();

                this.hCalculatorList.Add(new List <MAM_HeuristicCalculator>());
                this.hCalculatorList[agent.agentIndex].Add(hCalculator);

                if (costFunction == CostFunction.SOC || hCalculator is ZeroHCalculator)
                {
                    continue;
                }
                foreach (MAM_AgentState agent2 in this.instance.m_vAgents)      // set all pairs of agents (for makespan heurisic)
                {
                    if (agent == agent2)
                    {
                        continue;
                    }
                    MAM_HeuristicCalculator newHeuristicCalculator = hCalculator.copyHeuristicCalculator();
                    MAM_AgentState[]        agentStartStates       = new MAM_AgentState[2];
                    agentStartStates[0] = agent;
                    agentStartStates[1] = agent2;
                    ProblemInstance subProblem = instance.CreateSubProblem(agentStartStates);
                    newHeuristicCalculator.init(subProblem);
                    this.hCalculatorList[agent.agentIndex].Add(newHeuristicCalculator);
                }
            }
        }
Beispiel #2
0
 private void CalculateH
 (
     MAM_AgentState state,
     MAM_AgentState prev
 )
 {
     state.h = 0;
     if (hCalculatorList[0][0] is ZeroHCalculator)
     {
         return;
     }
     if (costFunction == CostFunction.MakeSpan)
     {
         for (int heuristicCalculatorIndex = 0; heuristicCalculatorIndex < hCalculatorList[state.agentIndex].Count; heuristicCalculatorIndex++)
         {
             MAM_HeuristicCalculator heuristicCalculator = hCalculatorList[state.agentIndex][heuristicCalculatorIndex];
             MAM_AgentState          newState            = new MAM_AgentState(state);
             MAM_AgentState          newPrevState        = null;
             if (prev != null)
             {
                 newPrevState   = new MAM_AgentState(prev);
                 newPrevState.h = prev.heuristics[heuristicCalculatorIndex];
             }
             state.heuristics.Add(heuristicCalculator.h(newState, newPrevState));
             double makespan1 = (state.h + state.g) / state.numOfAgentsInBestHeuristic;
             double makespan2 = (state.heuristics[heuristicCalculatorIndex] + state.g) / heuristicCalculator.GetNumberOfAgents();
             if (makespan1 < makespan2)
             {
                 state.h = state.heuristics[heuristicCalculatorIndex];
                 state.numOfAgentsInBestHeuristic = heuristicCalculator.GetNumberOfAgents();
             }
         }
     }
     else if (costFunction == CostFunction.SOC)
     {
         state.h = hCalculatorList[0][0].h(state, prev);
     }
 }