-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProportionalHeuristic.java
147 lines (136 loc) · 3.86 KB
/
ProportionalHeuristic.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Write a description of class ProportionalHeuristic here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ProportionalHeuristic
{
// instance variables - replace the example below with your own
private int x;
/**
* Constructor for objects of class ProportionalHeuristic
*/
public ProportionalHeuristic()
{
// initialise instance variables
x = 0;
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public int sampleMethod(int y)
{
// put your code here
int index[];
index = new int[(int)n+1];
for (int i = 0; i <= n; i++)
{
index[i] = 0;
}
double NC = Math.pow((lam_max+1), n);
System.out.println(NC);
for (int i = 0; i < maxrow; i++)
{
diff_sum[i] = 0;
}
count_iter = 0;
for ( count = 1; count <= NC; count++ )
{
if ( count == 1 )
{
for ( count2 = 1; count2 <= n; count2++ )
{
index[count2] = 0;
}
}
else
{
position = (int)n;
while ( index[position] == lam_max )
{
position--;
}
index[position]++;
for (count3 = position+1; count3 <= n; count3++ )
{
index[count3] = 0;
}
}
double total_veh=0;
for (int i=0; i<=n; i++)
{
veh_count[i] = 0;
prop_lam[i]=0;
}
for (int j=0; j<=lam_max; j++)
{
for (int i=0; i<=n; i++)
{
if (lambda[j][i] > 0)
{
veh_count[i]++;
total_veh++;
}
}
}
for (int i = 0; i <= n; i++)
{
prop_lam[i] = (veh_count[i])/total_veh;
}
for ( count2 = 0; count2 <= n ; count2++)
{
lam_sol[count2] = lambda[index[count2]][count2];
}
int flag = 1;
for (int count6 = 1; count6 <= n; count6++)
{
if (lam_sol[count6] < lam_sol[(count6 - 1)])
flag = 0;
}
if (flag == 1)
{
for (int count6 = 0; count6 < n; count6++)
{
//System.out.println(count_iter + " " + count6 );
diff_sum[count_iter] += Math.abs(lam_sol[count6] - prop_lam[count6]);
lam_combo[count_iter][count6] = lam_sol[count6];
}
count_iter++;
}
}
for (count=0; count<count_iter; count++)
{
if (diff_sum[count] > diff_sum[count+1])
{
temp1 = diff_sum[count];
for (count2=0; count2<=n; count2++)
{
temp2[count2] = lam_combo[count][count2];
}
diff_sum[count]=diff_sum[count+1];
for (count2=0; count2<=n; count2++)
{
lam_combo[count][count2] = lam_combo[count+1][count2];
}
diff_sum[count+1]=temp1;
for (count2=0; count2<=n; count2++)
{
lam_combo[count+1][count2] = temp2[count2];
}
}
}
if (count_iter < 500)
{
count3 = (count_iter - 1);
}
else
{
count3 = 500;
}
//leap = 0;
}
}