-
Notifications
You must be signed in to change notification settings - Fork 3
/
CbsCacheEntry.cs
50 lines (44 loc) · 1.69 KB
/
CbsCacheEntry.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
using System.Collections.Generic;
using System.Diagnostics;
namespace mapf
{
public class CbsCacheEntry
{
protected CbsNode cbsNode;
protected int agentIndex;
public CbsCacheEntry(CbsNode cbsNode, int agentIndex)
{
this.cbsNode = cbsNode;
this.agentIndex = agentIndex;
Trace.Assert(cbsNode.cbs.mergeThreshold == -1, "When agents are merged it affects their paths without explicit constraints");
}
public override int GetHashCode()
{
unchecked
{
int ans = 0;
HashSet<CbsConstraint> constraints = this.cbsNode.GetConstraints();
// Add the hash codes for the contraints, ignoring their order
foreach (CbsConstraint constraint in constraints)
{
if (constraint.agentNum == this.agentIndex)
ans += constraint.GetHashCode();
}
return ans;
}
}
public override bool Equals(object obj)
{
if (obj == null)
return false;
CbsCacheEntry other = (CbsCacheEntry)obj;
if (this.agentIndex != other.agentIndex)
return false;
HashSet<CbsConstraint> constraints = this.cbsNode.GetConstraints();
constraints.RemoveWhere(constraint => constraint.agentNum != this.agentIndex);
HashSet<CbsConstraint> otherConstraints = other.cbsNode.GetConstraints();
otherConstraints.RemoveWhere(constraint => constraint.agentNum != other.agentIndex);
return constraints.SetEquals(otherConstraints);
}
}
}