In [ ]:
# Author: Brian Busemeyer.
# bbusemeyer@gmail.com

In [1]:
from imp import reload
import cProfile
import re
import gen_alg as ga
import numpy as np
import matplotlib.pyplot as plt
import time
import plot_tools as pt
%matplotlib inline

In [27]:
# Statistics of generating bin-packing problems.
fig,ax = plt.subplots(1,3,sharex=False,sharey=True)
statmult = 40
greedytypes = ['sorted','unsorted','backwards']
for aidx,a in enumerate(ax):
ga.greedy_hist(fig,a,size=100,order=greedytypes[aidx],stats=8*statmult)
a.set_xlabel("Filling fraction")
a.set_title(greedytypes[aidx])
a.set_xticks(pt.thin_ticks(a.get_xticks(),div=2,start=1))
ax[0].set_ylabel("Fraction of studies")
fig.set_size_inches(6,2.5)
fig.tight_layout()
fig.savefig("greedy_stat.eps")

In [3]:
# Statistics of generating bin-packing problems.
ga.stat_greedy(order='sorted',size=100,stats=300)

Out[3]:
0.94668152307140019
In [4]:
# Greedy solution properties as function of number of packages.
fig,ax = plt.subplots(1,1)
statmult = 40
fig,ax = ga.plot_size_trend(fig,ax,np.arange(2,7),stats=8*statmult,size=100)
ax.set_xlabel("Number of packages")
ax.set_ylabel("Fill fraction")
ax.legend(loc='best',frameon=True)
fig.tight_layout()

In [ ]:
reload(ga)
fig,ax = plt.subplots(1,1)
ga.test_genalg(fig,ax,100,20,50,0.5)
ax.set_xlabel("Generation")
ax.set_ylabel("Volume fraction")
fig.tight_layout()
fig.savefig("demo.eps")

In [54]:
reload(ga)
fig,ax = plt.subplots(1,2,sharex=True,sharey=False)
stat_mult = 1
ga.greedy_hist(fig,ax[0],size=8*stat_mult,order='sorted',stats=300)
ga.genalg_hist(fig,ax[1],stats=8*stat_mult,max_gens=100,popsize=20,npackages=50,max_package=0.5)
for a in ax:
a.set_xlabel("Volume fraction")
a.set_xticks(pt.thin_ticks(a.get_xticks(),shift=1))
ax[0].set_ylabel("Fraction of runs")
fig.tight_layout()
fig.savefig("genalg_stats.eps")

In [46]:
reload(ga)
fig, ax = plt.subplots(1,1)
statmult=10
ga.scan_max_package(fig,ax,stats=8*statmult,max_gens=100,popsize=20,npackages=50,max_packages=np.linspace(0.1,1.0,10))
ax.set_xlabel("Max package size")
ax.set_ylabel("Volume fraction")
fig.set_size_inches(4,3)
fig.tight_layout()
fig.savefig("scan_max_packages.eps")

Done with  0.1
Done with  0.2
Done with  0.3
Done with  0.4
Done with  0.5
Done with  0.6
Done with  0.7
Done with  0.8
Done with  0.9
Done with  1.0

In [56]:
reload(ga)
fig, ax = plt.subplots(1,1)
statmult=5
ga.scan_popsize(fig,ax,stats=8*statmult,max_gens=100,popsizes=np.arange(10,100,10,dtype=int),
npackages=50,max_package=0.5)
ax.set_xlabel("Number of packages")
ax.set_ylabel("Volume fraction")
fig.set_size_inches(4,3)
fig.tight_layout()
fig.savefig("scan_popsize.eps")

Done with  10
Done with  20
Done with  30
Done with  40
Done with  50
Done with  60
Done with  70
Done with  80
Done with  90

In [55]:
reload(ga)
fig, ax = plt.subplots(1,1)
statmult = 5
ga.scan_npackages(fig,ax,stats=8*statmult,max_gens=100,popsize=20,
npackagess=np.arange(10,100,10,dtype=int),max_package=0.5)
ax.set_xlabel("Number of packages")
ax.set_ylabel("Volume fraction")
fig.set_size_inches(4,3)
fig.tight_layout()
fig.savefig("scan_npackagess.eps")

Done with  10
Done with  20
Done with  30
Done with  40
Done with  50
Done with  60
Done with  70
Done with  80
Done with  90