-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
62 lines (57 loc) · 1.79 KB
/
Main.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
59
60
61
62
import java.util.*;
import PolicyFolder.*;
import PolicyFolder.ValueFunctionFolder.*;
public class Main{
public static void main(String[] args) {
boolean firstIteration = true;
int row, col, numOfGoals;
int[] goal;
Scanner scan = new Scanner(System.in);
System.out.print("Enter number of rows: ");
row = scan.nextInt();
System.out.print("Enter number of columns: ");
col = scan.nextInt();
System.out.print("Enter number of goals: ");
numOfGoals = scan.nextInt();
goal = new int[2*numOfGoals];
for(int i=0;i<numOfGoals;i++){
System.out.print("Enter row number of goal " + (i+1) + ": ");
goal[2*i] = scan.nextInt();
System.out.print("Enter column number of goal " + (i+1) + ": ");
goal[2*i+1] = scan.nextInt();
}
System.out.println();
System.out.println();
ValueFunction valueFunction = new ValueFunction(row,col,goal);
Policy oldPolicy = new Policy(row,col,goal);
Policy newPolicy = new Policy(row,col,goal);
while(!oldPolicy.equals(newPolicy) || firstIteration){
System.out.println();
if(firstIteration){
System.out.println("Value Function: ");
valueFunction.printValueFunction();
System.out.println();
System.out.println("Policy: ");
newPolicy.printPolicy();
firstIteration = false;
valueFunction.updateValueMatrix();
newPolicy.updatePolicy(valueFunction);
}
else{
System.out.println();
System.out.println("Value Function: ");
valueFunction.printValueFunction();
System.out.println();
System.out.println("Policy: ");
newPolicy.printPolicy();
oldPolicy.copy(newPolicy.returnPolicyMatrix());
valueFunction.updateValueMatrix();
newPolicy.updatePolicy(valueFunction);
}
}
System.out.println();
System.out.println("Final Result: ");
newPolicy.printConvertedPolicy();
System.out.println();
}
}