(int i1, int i2, ExecutorService ex, int P)
| 153 | |
| 154 | |
| 155 | private boolean takeStep(int i1, int i2, ExecutorService ex, int P) throws InterruptedException, ExecutionException |
| 156 | { |
| 157 | //these 2 will hold the old values |
| 158 | final double alph1 = alphas[i1]; |
| 159 | final double alph2 = alphas[i2]; |
| 160 | double F1 = fcache[i1]; |
| 161 | double F2 = fcache[i2]; |
| 162 | double gamma = alph1+alph2; |
| 163 | |
| 164 | final double k11 = kEval(i1, i1); |
| 165 | final double k12 = kEval(i2, i1); |
| 166 | final double k22 = kEval(i2, i2); |
| 167 | |
| 168 | final double eta = 2*k12-k11-k22; |
| 169 | final double a2 = alph2-(F1-F2)/eta; |
| 170 | if(abs(a2-alph2) < epsilon*(a2+alph2+epsilon)) |
| 171 | return false; |
| 172 | final double a1 = gamma-a2; |
| 173 | alphas[i1] = a1; |
| 174 | alphas[i2] = a2; |
| 175 | |
| 176 | //Update the DualObjectiveFunction using (4.11) |
| 177 | double t = (F1-F2)/eta; |
| 178 | dualObjective -= eta/2*t*t; |
| 179 | |
| 180 | //2 steps done in the same loop |
| 181 | b_up = Double.NEGATIVE_INFINITY; |
| 182 | b_low = Double.POSITIVE_INFINITY; |
| 183 | |
| 184 | //Update Fcache[i] for all i in I using (4.10) |
| 185 | //Compute (i_low, b_low) and (i_up, b_up) using (3.4) |
| 186 | |
| 187 | List<Future<PairedReturn<Integer, Integer>>> futures = new ArrayList<Future<PairedReturn<Integer, Integer>>>(P); |
| 188 | for(int id = 0; id < P; id++) |
| 189 | { |
| 190 | int from = getStartBlock(fcache.length, id, P); |
| 191 | int to = getEndBlock(fcache.length, id, P); |
| 192 | futures.add(ex.submit(new TakeStepLoop(from, to, i1, i2, alph1, alph2))); |
| 193 | } |
| 194 | for(Future<PairedReturn<Integer, Integer>> fpr : futures) |
| 195 | { |
| 196 | PairedReturn<Integer, Integer> pr = fpr.get(); |
| 197 | int i_up_cand = pr.getFirstItem(); |
| 198 | int i_low_cand = pr.getSecondItem(); |
| 199 | if(fcache[i_up_cand] > b_up) |
| 200 | { |
| 201 | b_up = fcache[i_up_cand]; |
| 202 | i_up = i_up_cand; |
| 203 | } |
| 204 | |
| 205 | if(fcache[i_low_cand] < b_low) |
| 206 | { |
| 207 | b_low = fcache[i_low_cand]; |
| 208 | i_low = i_low_cand; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | return true; |
no test coverage detected