In [32]:
from __future__ import print_function

%matplotlib inline
%load_ext autoreload
%autoreload 2

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import numpy as np
import tables as t
from collections import defaultdict
import os
from cyclopts import tools as tools
from cyclopts import cyclopts_io as cycio
from cyclopts import analysis
from cyclopts.analysis import Context, RatioContext, ipastels


The autoreload extension is already loaded. To reload it, use:
  %reload_ext autoreload

In [33]:
# configurable input
mod_kind = 'reqr' # rxtr or reqr or rand
frxtr = 0
xchange = {'reqr': 'Reactor Supply', 'rxtr': 'Reactor Demand'}
base = '~/phd/cyclopts/structured_runs/'
savename = '{0}_{1}_{2}_{3}_ratios.png'

if mod_kind == 'rxtr':
    species_module = "cyclopts.structured_species.request"
    species_class = "StructuredRequest"
elif mod_kind == 'reqr':
    species_module = "cyclopts.structured_species.supply"
    species_class = "StructuredSupply"  
elif mod_kind == 'rand':
    species_module = "cyclopts.random_request_species"
    species_class = "RandomRequest"   

family_module = "cyclopts.exchange_family"
family_class = "ResourceExchange"
fname = 'combined.h5'

In [34]:
dirnames = ['ratio_0_1_{kind}_{frxtr}', 'base_{kind}_{frxtr}', 'ratio_10_{kind}_{frxtr}', 'ratio_50_{kind}_{frxtr}']
ratios = [0.1, 1, 10, 50]

dirnames = [x.format(kind=mod_kind, frxtr=frxtr) for x in dirnames]
files = [os.path.join(os.path.join(os.path.expanduser(base), x), fname) for x in dirnames]
fmask = [not os.path.exists(x) for x in files]

save = False
savepath = './ratio_pngs'
saveprefix = '{kind}_{frxtr}'.format(kind=mod_kind, frxtr=frxtr)
files = tools.masked_filter(files, fmask, unmask=True)
labels = ['{}%'.format(x) for x in tools.masked_filter(ratios, fmask, unmask=True)]

In [35]:
ctx = RatioContext(files, labels, family_module, family_class, species_module, species_class, 
                   save=save, savepath=savepath, saveprefix=saveprefix)
title = 'Solution Times for Different Convergence Criteria'
param = 'n_arcs'
savename = '{0}_{1}_{2}_{3}_ratios.png'
solver = 'cbc'
names = ['both', 'below', 'above']
lim = 3 * 60 * 60
above = [None, None, lim]
below = [None, lim, None]

In [36]:
param = 'n_arcs'
for i in range(len(names)):
    fig, ax = ctx.ratio_scatter(param, solver, save=save, 
                                savename=savename.format(mod_kind, frxtr, names[i], param), 
                                above=above[i], below=below[i], title=title)



In [37]:
param = 'n_constrs'
for i in range(len(names)):
    fig, ax = ctx.ratio_scatter(param, solver, save=save, 
                                savename=savename.format(mod_kind, frxtr, names[i], param), 
                                above=above[i], below=below[i], title=title)



In [38]:
lim = 3 * 60 * 60
fig, ax = ctx.count_hist('cbc', lim, save=save)
fig.savefig('counthist.png')



In [38]:


In [38]:


In [38]:


In [39]:
fig, ax = ctx.popn_hist(lim=lim, zone='a', idxs=[0, 1], bins=50, alpha=0.5)



In [40]:
fig, ax = ctx.popn_hist(lim=lim, zone='b', bins=50, alpha=0.5)



In [41]:
fig, ax = ctx.popn_hist(lim=lim, zone='c', bins=50, alpha=0.5)



In [42]:
fig, ax = ctx.group_popn_hist(zone='a', alpha=0.5)
fig.savefig('a.png')



In [43]:
fig, ax = ctx.group_popn_hist(zone='b', alpha=0.5)
fig.savefig('b.png')



In [44]:
fig, ax = ctx.group_popn_hist(zone='c', alpha=0.5)
fig.savefig('c.png')



In [44]: