-
Notifications
You must be signed in to change notification settings - Fork 4
/
Driver.java
executable file
·41 lines (37 loc) · 1.44 KB
/
Driver.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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Driver {
public static int noItems;
public static double[] value;
public static double[] weight;
public static double knapsackSize;
public static int populationSize;
public static int maxGenerations;
public static double crossProb;
public static double mutatProb;
public static void main(String[] args){
readInit("init.txt");
KnapSackGA knapsack = new KnapSackGA(noItems, value, weight, knapsackSize, populationSize, maxGenerations, crossProb, mutatProb);
}
private static void readInit(String filename){
try {
Scanner input = new Scanner(new File(filename));
noItems = input.nextInt();
value = new double[noItems];
weight = new double[noItems];
for(int i = 0; i < noItems; i++)
value[i] = input.nextDouble();
for(int i = 0; i < noItems; i++)
weight[i] = input.nextDouble();
knapsackSize = input.nextDouble();
populationSize= input.nextInt();
maxGenerations = input.nextInt();
crossProb = input.nextDouble();
mutatProb = input.nextDouble();
} catch (FileNotFoundException ex) {
System.err.println("File not found!");
System.exit(1);
}
}
}