-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRouteFunction.java
More file actions
50 lines (37 loc) · 989 Bytes
/
Copy pathRouteFunction.java
File metadata and controls
50 lines (37 loc) · 989 Bytes
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
package lcll;
import java.util.List;
import org.gava.ObjectiveFunction;
public class RouteFunction implements ObjectiveFunction<Integer> {
private int length;
private double[][] map;
private int maxWeight;
/**
* Constructor para inicialización de ruta
* @param map Matriz cuadrada con los pesos de cada arista
* @param maxW Peso máximo introducido de alguna arista
* @param length No. de nodos
*/
public RouteFunction(double[][] map, int maxW, int length) {
this.map = map;
this.maxWeight = maxW ;
this.length = length;
}
@Override
public int length() {
return this.length;
}
/**
* Se recibe una ruta especifica y se calcula el peso de la ruta
*/
@Override
public Double function(List<Integer> route) {
double sum = 0;
for(int i = 0; i < route.size() - 1; i++) {
sum += map[route.get(i)-1][route.get(i+1)-1];
}
return sum;
}
public int getMaxWeight() {
return maxWeight;
}
}