Skip to content
Permalink
915e5cc167
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
62 lines (48 sloc) 1.77 KB
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;
}
}