-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHillClimbing.java
58 lines (50 loc) · 1.26 KB
/
HillClimbing.java
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
/**
* Hill Climbing ALgorithm
* Author: Sekar Anglila Hapsari
* Date: 25 September 2016
*/
package jadwal;
import jadwal.Graph;
public class HillClimbing{
private Graph graph;
public HillClimbing(Graph G){
this.graph = G;
}
private Graph getMin(Graph[] LGraph){
Graph GMin = LGraph[0];
for (int i = 1; i < LGraph.length; i++){
if (GMin.getConflicts() <= LGraph[i].getConflicts()){
GMin = LGraph[i];
}
}
return GMin;
}
public Graph HillClimb(Graph G){
//Kamus
boolean finish = false;
Graph GCurrent = new Graph(G);
//Algoritma
while (!finish){
Graph[] LGraph = new Graph[100];
for (int v = 0; v < GCurrent.getVariables().length; v++){
for (int d = 0; d < GCurrent.getVariables[v].getDomainList().size(); d++){
Domain a = GCurrent.getVariables[v].getDomainList[d];
if (isSame(a, GCurrent.getVariables[v].getCurrDomain())) {
//do nothing
} else {
Graph GCopy = new Graph(GCurrent);
GCopy.getVariables[v].setCurrDomain(d);
LGraph.add(Graph(GCopy));
}
}
}
Graph GMin = getMin(LGraph));
if (GMin.getConflicts() <= GCurrent.getConflicts()){
GCurrent = Gmin;
} else {
finish = true;
}
}
return GCurrent;
}
}