1 | package geniusweb.ip.ipSolver;
|
---|
2 |
|
---|
3 | import geniusweb.ip.dpSolver.DPSolver;
|
---|
4 | import geniusweb.ip.inputOutput.Input;
|
---|
5 | import geniusweb.ip.inputOutput.SolverNames;
|
---|
6 | import geniusweb.ip.mainSolver.Result;
|
---|
7 |
|
---|
8 | public class IDPSolver_whenRunning_ODPIP extends Thread {
|
---|
9 | private Input inputToIDPSolver;
|
---|
10 | private Result result;
|
---|
11 | private double[] valueOfBestPartitionFound;
|
---|
12 | private boolean stop = false;
|
---|
13 | public DPSolver dpSolver;
|
---|
14 |
|
---|
15 | public void setStop(boolean value) {
|
---|
16 | if (dpSolver != null)
|
---|
17 | dpSolver.setStop(value);
|
---|
18 | stop = value;
|
---|
19 | }
|
---|
20 |
|
---|
21 | // *****************************************************************************************************
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * The constructor
|
---|
25 | */
|
---|
26 | public IDPSolver_whenRunning_ODPIP(Input input, Result result) {
|
---|
27 | this.stop = false;
|
---|
28 | this.result = result;
|
---|
29 | this.valueOfBestPartitionFound = new double[1 << input.numOfAgents];
|
---|
30 |
|
---|
31 | // Initialize the input to, and the result of, the IDP solver
|
---|
32 | this.inputToIDPSolver = getInputToIDPSolver(input);
|
---|
33 |
|
---|
34 | // Run the IDP solver
|
---|
35 | this.dpSolver = new DPSolver(inputToIDPSolver, result);
|
---|
36 | }
|
---|
37 |
|
---|
38 | // *****************************************************************************************************
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Synchronized set method
|
---|
42 | */
|
---|
43 | public synchronized void updateValueOfBestPartitionFound(int coalition,
|
---|
44 | double value) {
|
---|
45 | if (valueOfBestPartitionFound[coalition] < value)
|
---|
46 | valueOfBestPartitionFound[coalition] = value;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * get method
|
---|
51 | */
|
---|
52 | public double getValueOfBestPartitionFound(int coalition) {
|
---|
53 | return valueOfBestPartitionFound[coalition];
|
---|
54 | }
|
---|
55 |
|
---|
56 | // *****************************************************************************************************
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * This method uses IDP to compute parts of the table used in the
|
---|
60 | * local-branch-and-bound technique
|
---|
61 | */
|
---|
62 | @Override
|
---|
63 | public void run() {
|
---|
64 | this.dpSolver.runDPorIDP();
|
---|
65 | }
|
---|
66 |
|
---|
67 | // *****************************************************************************************************
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Initialize the array "valueOfBestPartitionFound" such that, for every
|
---|
71 | * coalition C, we simply put: valueOfBestPartitionFound[C] = v[C]
|
---|
72 | */
|
---|
73 | public void initValueOfBestPartitionFound(Input input,
|
---|
74 | double[][] maxValueForEachSize) {
|
---|
75 | long startTime = System.currentTimeMillis();
|
---|
76 |
|
---|
77 | valueOfBestPartitionFound[0] = 0;
|
---|
78 |
|
---|
79 | // initialize result.max_f. Basically, result.max_f[3] is the maximum f
|
---|
80 | // value that DP computed for a coalition of size 4
|
---|
81 | result.init_max_f(input, maxValueForEachSize);
|
---|
82 |
|
---|
83 | // Initialize the best partition of each coalition C to be the maximum
|
---|
84 | // between
|
---|
85 | // its value, and the sum of values of the singletons made of its
|
---|
86 | // members.
|
---|
87 | for (int coalitionInBitFormat = valueOfBestPartitionFound.length
|
---|
88 | - 1; coalitionInBitFormat >= 1; coalitionInBitFormat--)
|
---|
89 | valueOfBestPartitionFound[coalitionInBitFormat] = input
|
---|
90 | .getCoalitionValue(coalitionInBitFormat);
|
---|
91 |
|
---|
92 | // System.out.println("The time required to initialize the
|
---|
93 | // local-branch-and-bound table is
|
---|
94 | // "+(System.currentTimeMillis()-startTime)+" millisec");
|
---|
95 | }
|
---|
96 |
|
---|
97 | // *****************************************************************************************************
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Initialize the parameters of the input object to be passed to the DP
|
---|
101 | * solver
|
---|
102 | */
|
---|
103 | private Input getInputToIDPSolver(Input input) {
|
---|
104 | Input inputToDPSolver = new Input(input.numOfAgents,
|
---|
105 | input.coalitionValues, input.acceptableRatio);
|
---|
106 | // inputToDPSolver.coalitionValues = input.coalitionValues;
|
---|
107 | inputToDPSolver.problemID = input.problemID;
|
---|
108 |
|
---|
109 | // The DP parameters
|
---|
110 | inputToDPSolver.solverName = SolverNames.ODPIP;
|
---|
111 |
|
---|
112 | // The printing parameters
|
---|
113 | inputToDPSolver.storeCoalitionValuesInFile = false;
|
---|
114 | inputToDPSolver.printDetailsOfSubspaces = false;
|
---|
115 | inputToDPSolver.printNumOfIntegerPartitionsWithRepeatedParts = false;
|
---|
116 | inputToDPSolver.printInterimResultsOfIPToFiles = false;
|
---|
117 | inputToDPSolver.printTimeTakenByIPForEachSubspace = false;
|
---|
118 |
|
---|
119 | // General parameters
|
---|
120 | inputToDPSolver.feasibleCoalitions = null;
|
---|
121 | // inputToDPSolver.numOfAgents = input.numOfAgents;
|
---|
122 | inputToDPSolver.numOfRunningTimes = 1;
|
---|
123 |
|
---|
124 | return (inputToDPSolver);
|
---|
125 | }
|
---|
126 | } |
---|