Skip to content

Commit

Permalink
"compression" works
Browse files Browse the repository at this point in the history
  • Loading branch information
PtrMan committed Dec 9, 2015
1 parent f99942a commit 6ff085c
Showing 1 changed file with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,51 @@ public static void main(String[] args) throws Exception {

DecoratedCausalGraph causalGraph = ConvertInputGraphToCausalGraph.convert(inputGraph);

//ArrayList<Integer> result = TrackbackGenerator.generate(new Random(), causalGraph);

EnergyMinimizer.State state = new EnergyMinimizer.State();
state.workingGraph = causalGraph;

EnergyMinimizer.minimize(new Random(), 50000, state);


int y = 0;

// visualize the result
ArrayList<Integer> resultIndices = state.minimalSequence;

for( int iterationIndex : resultIndices ) {
final int tokenIndex = getKeyByValue(tokensToGraphIndices, iterationIndex);

if( tokenIndex == -1 ) {
System.out.print("[] ");
}
else {
System.out.print(getTokenByIndex(tokenIndex, tokenMap));
System.out.print(" ");
}
}
System.out.println();

}

private static String getTokenByIndex(int tokenIndex, Map<String, Integer> tokenMap) {
for( Map.Entry<String, Integer> iterationEntry : tokenMap.entrySet() ) {
if( iterationEntry.getValue().intValue() == tokenIndex ) {
return iterationEntry.getKey();
}
}

throw new RuntimeException("Couldn't find token!");
}


private static int getKeyByValue(Map<Integer, Integer> tokensToGraphIndices, int index) {
Set<Map.Entry<Integer, Integer>> entrySet = tokensToGraphIndices.entrySet();
for( Map.Entry<Integer, Integer> iterationEntry : entrySet ) {
if( iterationEntry.getValue().intValue() == index ) {
return iterationEntry.getKey();
}
}
return -1;
}

private static void createOneToOneTokenToGraphIndices(Map<Integer, Integer> target, int number) {
Expand Down

0 comments on commit 6ff085c

Please sign in to comment.