Skip to content

Commit

Permalink
Adding heat map graph
Browse files Browse the repository at this point in the history
  • Loading branch information
jah12014 committed Feb 14, 2018
1 parent f068e98 commit 0272fc3
Show file tree
Hide file tree
Showing 8 changed files with 543 additions and 19 deletions.
2 changes: 1 addition & 1 deletion IncrementalMinimization/generate_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mergeData(data, index):
for row in data:
if new_data and new_data[-1][index] == row[index]:
old_row = new_data[-1]
count += 1
count += 1
for i in range(0, len(old_row)):
if i != index:
old_row[i] += (row[i] - old_row[i])/float(count) #running average
Expand Down
68 changes: 68 additions & 0 deletions IncrementalMinimization/record_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import numpy
import matplotlib.pyplot as pyplot
import plotly.plotly as plotly
import plotly.tools as plottls

import sys

xAxis = "Percentage of Time Passed"
yAxis = "Number of States"
title = "Progress of Symbolic Incremental Minimization"

testsfile = sys.argv[1]

def toNum(s):
if s.isdigit():
return int(s)
else:
return float(s)

with open(testsfile, "r") as f:
fStrings = f.read().split("\n")

title_row = fStrings[0].split(',')
x = [toNum(s) for s in title_row[1:-1] if s]

y = []
z = []
for row in fStrings[1:]:
if row:
row = row.split(",")
print(row)
states = toNum(row[0])
for percent in row[1:-1]:
z.append(toNum(percent))
y.append(states)


x = numpy.unique(x)
y = numpy.unique(y)
X,Y = numpy.meshgrid(x,y)
z = numpy.array(z)
Z = z.reshape(len(y),len(x))
print(y)
print(x)
print(Z)
pyplot.pcolormesh(X,Y,Z)
bar = pyplot.colorbar()
bar.set_label("Percentage of Minimization Completed")

"""
fig = pyplot.figure()
ax = fig.add_subplot(111)
ax.set_title(title)
plotly_fig = plottls.mpl_to_plotly(fig)
"""

"""
hexbins = pyplot.hexbin(x,y, gridsize=100, cmap = 'inferno')
pyplot.axis([xmin, xmax, ymin, ymax])
colorbar = pyplot.colorbar(hexbins)
"""

pyplot.title(title)
pyplot.ylabel(yAxis)
pyplot.xlabel(xAxis)
pyplot.xticks(range(0,110,10),["{}%".format(p) for p in title_row[1:-1]])
pyplot.savefig("heatmap.png", dpi=600)
Binary file added IncrementalMinimization/results/heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
165 changes: 165 additions & 0 deletions IncrementalMinimization/results/record_test.txt

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions IncrementalMinimization/src/DisjointSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,45 @@ public class DisjointSets <E>

private HashMap<E, E> parentMap;
private HashMap<E, Integer> rankMap;
private int size;

public DisjointSets()
{
parentMap = new HashMap<E, E>();
rankMap = new HashMap<E, Integer>();
size = 0;
}

public DisjointSets(Collection<E> identifiers)
{
parentMap = new HashMap<E, E>();
rankMap = new HashMap<E, Integer>();
size=0;
for(E identifier : identifiers)
{
make(identifier);
size++;
}
}

public DisjointSets(DisjointSets<E> disjointSets)
{
parentMap = new HashMap<E,E>();
rankMap = new HashMap<E, Integer>();
size=0;
HashMap<E, HashSet<E>> sets = disjointSets.getSets();
for (E iden : sets.keySet())
{
make(iden);
HashSet<E> set = sets.get(iden);
for (E elem : set)
{
if (elem != iden)
{
make(elem);
}
union(elem, iden);
}
}
}

Expand All @@ -37,6 +62,7 @@ public void make(E identifier) throws IllegalArgumentException
{
parentMap.put(identifier, null);
rankMap.put(identifier, 1);
size++;
}
else
{
Expand Down Expand Up @@ -97,6 +123,7 @@ else if (rank1 > rank2)
union_iden = iden2;
}
}
size--;
return union_iden;
}

Expand All @@ -120,6 +147,11 @@ public HashMap<E, HashSet<E>> getSets()
return sets;
}

public int size()
{
return size;
}

public String toString()
{
return getSets().toString();
Expand Down
48 changes: 41 additions & 7 deletions IncrementalMinimization/src/IncrementalMinimization.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static <P,S> SFA<P,S> incrementalMinimize(SFA<P,S> aut, BooleanAlgebra<P,
try
{
IncrementalMinimization<P,S> min = new IncrementalMinimization<P,S>(aut, ba);
return min.minimize(budget, upfront);
return min.minimize(budget, upfront, false);
}
catch(TimeBudgetExceeded e)
{
Expand All @@ -259,6 +259,9 @@ public static <P,S> SFA<P,S> incrementalMinimize(SFA<P,S> aut, BooleanAlgebra<P,
private HashSet<List<Integer>> neq;
private LinkedHashMap<Integer, Integer> distanceToFinalMap;
private StateComparator stateComp;
private Long startTime;
private LinkedHashMap<Long, Integer> record; //maps time stamps to number of states
private Long singularRecord = null;

public IncrementalMinimization(SFA<P,S> aut, BooleanAlgebra<P,S> ba) throws TimeoutException
{
Expand All @@ -272,6 +275,8 @@ public IncrementalMinimization(SFA<P,S> aut, BooleanAlgebra<P,S> ba) throws Time
this.neq = new HashSet<List<Integer>>(num_pairs, 0.9f); //won't exceed initial capacity
this.distanceToFinalMap = generateDistanceToFinalMap();
this.stateComp = new StateComparator();
this.startTime = null;
this.record = new LinkedHashMap<Long, Integer>();
}

private LinkedHashMap<Integer, Integer> generateDistanceToFinalMap()
Expand Down Expand Up @@ -351,13 +356,14 @@ private boolean isSinkState(Integer p)

private boolean isKnownNotEqual(Integer p, Integer q)
{
if (neq.contains(normalize(p,q)))
List<Integer> normalizedPair = normalize(p,q);
if (neq.contains(normalizedPair))
{
return true;
}
else if (!distanceToFinalMap.get(p).equals(distanceToFinalMap.get(q)))
{
neq.add(normalize(p,q));
neq.add(normalizedPair);
return true;
}
else
Expand Down Expand Up @@ -389,6 +395,12 @@ private SFA<P,S> mergeSFAStates(DisjointSets<Integer> equivClasses) throws Timeo
return minAut;
}

private void updateRecord(DisjointSets<Integer> equivClasses)
{
Long time = System.nanoTime();
record.put(time, equivClasses.getSets().size());
}

private void timeCheck(long endTime, DisjointSets<Integer> equivClasses) throws TimeoutException
{
if(System.nanoTime() > endTime)
Expand All @@ -406,16 +418,21 @@ private void timeCheck(long endTime, DisjointSets<Integer> equivClasses) throws
}
}

public SFA<P, S> minimize(long budget, boolean upfront)
public SFA<P, S> minimize(long budget, boolean upfront, boolean recordMinimization)
throws TimeoutException
{
long endTime = System.nanoTime() + budget;
this.startTime = System.nanoTime();
long endTime = startTime + budget;
if (endTime < 0) //indicates overflow
{
endTime = Long.MAX_VALUE;
}
if(aut.isEmpty())
{
if(recordMinimization)
{
this.singularRecord = System.nanoTime() - startTime;
}
return SFA.getEmptySFA(ba);
}
ArrayList<P> upfront_minterms = null;
Expand Down Expand Up @@ -477,8 +494,11 @@ else if(equivClasses.find(p) == equivClasses.find(q))
equivClasses.union(equivPair.get(0), equivPair.get(1));
//equivClasses.union(equivPair.get(0), equivPair.get(1));
}
if(recordMinimization)
{
updateRecord(equivClasses);
}
timeCheck(endTime, equivClasses);
//after equiv merging for soft time budget?
}
else
{
Expand All @@ -495,6 +515,20 @@ else if(equivClasses.find(p) == equivClasses.find(q))
return mergeSFAStates(equivClasses);
}


public LinkedHashMap<Long, Integer> getRecord() throws TimeoutException
{
LinkedHashMap<Long,Integer> actualRecord = new LinkedHashMap<Long, Integer>();
actualRecord.put(this.startTime, aut.stateCount());
if (singularRecord != null)
{
actualRecord.put(singularRecord, 1);
return actualRecord;
}
for(Long time : record.keySet())
{
actualRecord.put(time, record.get(time));
}
return actualRecord;
}

}
36 changes: 33 additions & 3 deletions IncrementalMinimization/src/TestDisjointSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,40 @@ public void testUnion()
Assert.assertEquals(sets.find(1), sets.find(2));
Assert.assertEquals(new Integer(1),sets.find(1));
Assert.assertEquals(new Integer(1),sets.find(2));
sets.union(4, 5);
sets.union(2, 4);
Assert.assertEquals(sets.find(1), sets.find(5));
Assert.assertFalse(sets.find(1).equals(sets.find(7)));
}

@Test
public void testSize()
{
initialize();
Assert.assertEquals(10, sets.size());
sets.union(1, 2);
Assert.assertEquals(9, sets.size());
sets.union(4, 5);
sets.union(2, 4);
Assert.assertEquals(7, sets.size());
}

@Test
public void testCopy()
{
initialize();
sets.union(1, 2);
sets.union(3, 4);
sets.union(2, 3);
Assert.assertEquals(sets.find(1), sets.find(4));
Assert.assertFalse(sets.find(1).equals(sets.find(5)));
sets.union(5, 4);
DisjointSets<Integer> newSets = new DisjointSets<Integer>(sets);
Integer oneIden = newSets.find(1);
Assert.assertTrue(oneIden == 2 || oneIden == 1);
Integer fiveIden = newSets.find(5);
Assert.assertTrue(fiveIden == 3 || fiveIden == 4 || fiveIden == 5);
for (Integer i = 6; i < 10; i++)
{
Assert.assertEquals(sets.find(i), newSets.find(i));
}
}

}
Loading

0 comments on commit 0272fc3

Please sign in to comment.