-
Notifications
You must be signed in to change notification settings - Fork 3
/
SumIndividualCosts.cs
180 lines (157 loc) · 5.84 KB
/
SumIndividualCosts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using System.IO;
using System.Linq;
namespace mapf
{
/// <summary>
/// This class forms a wrapper around problem.GetSingleAgentOptimalCost().
/// It represents the single shortest path heuristic, precomputed for every agent.
/// </summary>
[Serializable]
class SumIndividualCosts : PDB
{
/// <summary>
/// Since this class simply refers via a table-lookup to the globally
/// available problem.GetSingleAgentOptimalCost class, we incur no memory.
/// </summary>
/// <returns>0 by definition.</returns>
public override UInt64 estimateSize()
{
return 0;
}
/// <summary>
/// The building function for this class doesn't do anything because we
/// are simply wrapping the functionality of the problem.GetSingleAgentOptimalCost
/// class.
/// </summary>
public override void build() {}
/// <summary>
/// Returns the heuristic estimate.
/// </summary>
/// <param name="s">The current state.</param>
/// <returns>The PDB entry for the given state.</returns>
public override uint h(WorldState s)
{
return h(s, this.problem);
}
public static uint h(WorldState s, ProblemInstance instance)
{
uint nHeuristic = 0;
foreach (AgentState state in s.allAgentsState)
{
nHeuristic += (uint)instance.GetSingleAgentOptimalCost(state);
}
return nHeuristic;
}
public override string ToString()
{
return "SIC";
}
/// <summary>
/// Prints header of statistics of a single run to the given output.
/// </summary>
public override void OutputStatisticsHeader(TextWriter output) { }
/// <summary>
/// Prints statistics of a single run to the given output.
/// </summary>
public override void OutputStatistics(TextWriter output) { }
public override int NumStatsColumns
{
get
{
return 0;
}
}
/// <summary>
/// Clears statistics.
/// </summary>
public override void ClearStatistics() { }
public override void ClearAccumulatedStatistics() { }
public override void AccumulateStatistics() { }
public override void OutputAccumulatedStatistics(TextWriter output) { }
}
/// <summary>
/// This class forms a wrapper around problem.GetSingleAgentOptimalCost().
/// It represents the single shortest path heuristic for makespan, precomputed for every agent.
/// </summary>
[Serializable]
class MaxIndividualCosts : PDB
{
/// <summary>
/// Since this class simply refers via a table-lookup to the globally
/// available problem.GetSingleAgentOptimalCost class, we incur no memory.
/// </summary>
/// <returns>0 by definition.</returns>
public override UInt64 estimateSize()
{
return 0;
}
/// <summary>
/// The building function for this class doesn't do anything because we
/// are simply wrapping the functionality of the problem.GetSingleAgentOptimalCost
/// class.
/// </summary>
public override void build() { }
/// <summary>
/// Returns the heuristic estimate.
/// </summary>
/// <param name="s">The current state.</param>
/// <returns>The PDB entry for the given state.</returns>
public override uint h(WorldState s)
{
return h(s, this.problem);
}
public static uint h(WorldState s, ProblemInstance instance)
{
uint maxHeuristic = 0;
int agentIndexWithMaxEstimate = 0;
int i = 0;
foreach (AgentState state in s.allAgentsState)
{
uint heuristic = (uint)instance.GetSingleAgentOptimalCost(state);
if (heuristic > maxHeuristic)
{
maxHeuristic = heuristic;
agentIndexWithMaxEstimate = i;
}
i++;
}
if (s.GetType() == typeof(WorldStateWithOD))
{
var sWithOD = (WorldStateWithOD) s;
if (sWithOD.agentTurn != 0 && sWithOD.agentTurn <= agentIndexWithMaxEstimate)
maxHeuristic--; // Make the F of nodes non-decreasing. Otherwise the child node where the agent
// with the max estimate finally moves, and moves along its shortest path to the
// goal (decreasing the heuristic), will have a lower F than its parent (because
// the cost of the node is already updated after the first agent moves).
}
return maxHeuristic;
}
public override string ToString()
{
return "MIC";
}
/// <summary>
/// Prints header of statistics of a single run to the given output.
/// </summary>
public override void OutputStatisticsHeader(TextWriter output) { }
/// <summary>
/// Prints statistics of a single run to the given output.
/// </summary>
public override void OutputStatistics(TextWriter output) { }
public override int NumStatsColumns
{
get
{
return 0;
}
}
/// <summary>
/// Clears statistics.
/// </summary>
public override void ClearStatistics() { }
public override void ClearAccumulatedStatistics() { }
public override void AccumulateStatistics() { }
public override void OutputAccumulatedStatistics(TextWriter output) { }
}
}