-
Notifications
You must be signed in to change notification settings - Fork 16
/
RandomChoiceOfHeuristic.cs
97 lines (83 loc) · 2.51 KB
/
RandomChoiceOfHeuristic.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
using System;
using System.IO;
using System.Collections.Generic;
namespace mapf;
class RandomChoiceOfHeuristic<State> : IHeuristicCalculator<State>
{
protected IHeuristicCalculator<State> first;
protected IHeuristicCalculator<State> second;
protected double p;
protected Random rand;
/// <summary>
///
/// </summary>
/// <param name="first"></param>
/// <param name="second"></param>
/// <param name="p"></param>
/// <param name="seed"></param>
public RandomChoiceOfHeuristic(IHeuristicCalculator<State> first,
IHeuristicCalculator<State> second, double p, int seed = 0)
{
this.first = first;
this.second = second;
this.p = p;
this.rand = new Random(seed);
}
public override string ToString()
{
return $"RandomChoiceOfHeuristic({this.p}:{this.first} {1 - this.p}:{this.second})";
}
public string GetName()
{
return this.ToString();
}
public uint h(State s)
{
if (this.rand.NextDouble() < p)
return this.first.h(s);
else
return this.second.h(s);
}
public void Init(ProblemInstance pi, List<uint> agentsToConsider)
{
this.first.Init(pi, agentsToConsider);
this.second.Init(pi, agentsToConsider);
}
public virtual void OutputStatisticsHeader(TextWriter output)
{
this.first.OutputStatisticsHeader(output);
this.second.OutputStatisticsHeader(output);
}
public virtual void OutputStatistics(TextWriter output)
{
this.first.OutputStatistics(output);
this.second.OutputStatistics(output);
}
public virtual int NumStatsColumns
{
get
{
return this.first.NumStatsColumns + this.second.NumStatsColumns;
}
}
public virtual void ClearStatistics()
{
this.first.ClearStatistics();
this.second.ClearStatistics();
}
public virtual void ClearAccumulatedStatistics()
{
this.first.ClearAccumulatedStatistics();
this.second.ClearAccumulatedStatistics();
}
public virtual void AccumulateStatistics()
{
this.first.AccumulateStatistics();
this.second.AccumulateStatistics();
}
public virtual void OutputAccumulatedStatistics(TextWriter output)
{
this.first.OutputAccumulatedStatistics(output);
this.second.OutputAccumulatedStatistics(output);
}
}