Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2015jOpt/jOptJSRecover/src/jopt/js/spi/graph/arc/ForkSplit.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
62 lines (48 sloc)
1.77 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jopt.js.spi.graph.arc; | |
import java.util.concurrent.RecursiveAction; | |
import jopt.js.spi.graph.node.ResourceNode; | |
public class ForkSplit extends RecursiveAction { | |
/** | |
* | |
*/ | |
//private static final long serialVersionUID = 40260316212684492L; | |
private int[] target_ID; | |
private ResourceNode[] targets; | |
private int start; | |
private int end; | |
private ResourceNode[] main_targets; | |
// Constructor will just take the inputted values and set them to the | |
//private member variable | |
public ForkSplit(int _start, int _end, ResourceNode[] _targets, int[] _target_ID, ResourceNode[] _main_targets){ | |
this.start = _start; | |
this.end = _end; | |
this.target_ID = _target_ID; | |
this.targets = _targets; | |
this.main_targets = _main_targets; | |
} | |
@Override | |
// This function recursively forks the targets until they are separate. | |
// Then once they are all of them are computed at the same time. | |
protected void compute() { | |
if (end - start == 1){ // if each target has been forked then compute. | |
compute_directly(); | |
} | |
else{ // recursively split that task into two until each targets is separate. | |
invokeAll(new ForkSplit(this.start,(this.end+this.start)/2,this.targets,this.target_ID, this.main_targets), | |
new ForkSplit((this.end+this.start)/2,this.end,this.targets,this.target_ID, this.main_targets)); | |
} | |
} | |
// This method will run the for loop once each targets is forked | |
private void compute_directly(){ | |
for (int i = 0; i < targets.length; i++){ | |
if (target_ID[start] == targets[i].getID()){ | |
main_targets[start] = targets[i]; | |
break; | |
} | |
} | |
} | |
// This will return the targets to be saved in ForwardCheckArc.java | |
public ResourceNode[] get_main_targets(){ | |
return this.main_targets; | |
} | |
} |