-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
23 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,40 @@ | ||
package causalreasoningsystem; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Random; | ||
|
||
public class EnergyMinimizer | ||
{ | ||
public static class State | ||
{ | ||
public DecoratedCausalGraph workingGraph; // graph which is being modified | ||
public DecoratedCausalGraph graphWithMinimalEnergy; | ||
public int minimalEnergy = Integer.MAX_VALUE; | ||
public ArrayList<Integer> minimalSequence; | ||
} | ||
|
||
public static void minimize(Random random, int numberOfSteps, State state) throws Exception | ||
{ | ||
int step; | ||
|
||
for( step = 0; step < numberOfSteps; step++ ) | ||
{ | ||
minimizeSingleStep(random, state); | ||
} | ||
} | ||
|
||
private static void minimizeSingleStep(Random random, State state) throws Exception | ||
{ | ||
ArrayList<Integer> potentialMinimalSequence; | ||
|
||
potentialMinimalSequence = TrackbackGenerator.generate(random, state.workingGraph); | ||
state.workingGraph.updateEnergy(); | ||
|
||
if( state.workingGraph.energy < state.minimalEnergy ) | ||
{ | ||
state.minimalEnergy = state.workingGraph.energy; | ||
state.graphWithMinimalEnergy = state.workingGraph.clone(); | ||
state.minimalSequence = potentialMinimalSequence; | ||
} | ||
} | ||
} |
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