forked from CSE2102Fall2012Storrs/jOpt
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adding ForkSplit
- Loading branch information
Tony
authored and
Tony
committed
Dec 8, 2015
1 parent
03c63b1
commit 915e5cc
Showing
4 changed files
with
91 additions
and
17 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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; | ||
} | ||
|
||
} |
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
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