-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCbsConflict.cs
93 lines (87 loc) · 3.5 KB
/
CbsConflict.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
using System.Diagnostics;
namespace mapf
{
public class CbsConflict
{
public int agentAIndex; // Agent index and not agent num since this class is only used to represent internal conflicts
public int agentBIndex;
public Move agentAmove;
public Move agentBmove;
public int timeStep;
/// <summary>
/// If true, conflict is two agents have same dest, from any direction. Otherwise it's an edge conflict.
/// </summary>
public bool isVertexConflict;
public WillCostIncrease willCostIncreaseForAgentA;
public WillCostIncrease willCostIncreaseForAgentB;
public enum WillCostIncrease
{
MAYBE,
YES,
NO
}
public CbsConflict(int conflictingAgentAIndex, int conflictingAgentBIndex, Move agentAMove, Move agentBMove, int timeStep)
{
this.agentAIndex = conflictingAgentAIndex;
this.agentBIndex = conflictingAgentBIndex;
this.agentAmove = agentAMove;
this.agentBmove = agentBMove;
this.timeStep = timeStep;
if (agentAMove.x == agentBMove.x && agentAMove.y == agentBMove.y) // Same dest, from any direction
this.isVertexConflict = true;
else
{
this.isVertexConflict = false;
Trace.Assert(Constants.ALLOW_HEAD_ON_COLLISION == false, "Creating an edge conflict when head-on collision are allowed");
}
this.willCostIncreaseForAgentA = WillCostIncrease.MAYBE;
this.willCostIncreaseForAgentB = WillCostIncrease.MAYBE;
}
public override string ToString()
{
return $"Agent {this.agentAIndex} going {this.agentAmove} collides with agent " +
$"{this.agentBIndex} going {this.agentBmove} at time {this.timeStep}";
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
var other = (CbsConflict)obj;
if (this.agentAIndex != other.agentAIndex)
return false;
if (this.agentBIndex != other.agentBIndex)
return false;
if (this.isVertexConflict != other.isVertexConflict)
return false;
if (this.timeStep != other.timeStep)
return false;
if (this.isVertexConflict)
{ // Compare dests, ignore directions. Enough to compare one agent's move because the other is colliding with it.
if (this.agentAmove.x != other.agentAmove.x)
return false;
if (this.agentAmove.y != other.agentAmove.y)
return false;
}
else
{ // Compare dests and directions (unless direction is NO_DIRECTION)
if (this.agentAmove.Equals(other.agentAmove) == false)
return false;
if (this.agentBmove.Equals(other.agentBmove) == false)
return false;
}
return true;
}
public override int GetHashCode()
{
unchecked
{
return 2 * this.agentAIndex +
3 * this.agentBIndex +
5 * this.timeStep +
7 * this.isVertexConflict.GetHashCode() +
11 * this.agentAmove.GetHashCode() +
13 * this.agentBmove.GetHashCode();
}
}
}
}