In [1]:
import numpy as np
import pandas as pd
from pandas import DataFrame as df
from cylp.cy import CyClpSimplex
from cylp.py.modeling.CyLPModel import CyLPArray, CyLPModel
from Single_Year_Stage_II import Single_Year_Stage_II

In [2]:
puf = pd.read_csv("/Users/Amy/Documents/puf.csv")
Stage_I_factors = df.from_csv("Stage_I_factors.csv", index_col = 0)
Stage_II_targets = df.from_csv("Stage_II_targets.csv", index_col= 0)

In [3]:
length = len(puf.s006)
z = np.empty([length, 17])
z[:,0] = puf.s006/100

In [4]:
z[:,1] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2009', tol = 0.24)


Preparing coefficient matrix...
('Preparing targets for ', '2009')
('Targets for year ', '2009', ' is ', CyLPArray([ -1.64492002e+06,   3.18067705e+05,   3.53611665e+05,
         3.19150465e+05,   2.32556139e+06,   1.01792504e+10,
         5.78905487e+09,   6.09799850e+09,   3.44315381e+09,
         2.82354767e+10,   4.12114894e+10,   3.20750597e+10,
         3.37391347e+10,   5.58054245e+09,   2.15721621e+09,
         2.19716859e+09,  -2.38779176e+09,   1.49428392e+10,
         1.50270441e+10,   1.83876237e+10,   9.38012531e+09,
         1.92606474e+10,   2.73074004e+10,   7.12873034e+10,
         1.05169534e+10,  -1.09168518e+10,  -7.60076829e+10]))
Adding constraints
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/modeling/CyLPModel.py:372: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if left == None:
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/utils/sparseUtil.py:388: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if b == None:
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/utils/sparseUtil.py:387: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if a == None:
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/utils/sparseUtil.py:391: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if b == None:
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/modeling/CyLPModel.py:193: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if (other == None):
/Users/Amy/anaconda/lib/python2.7/site-packages/cylp-0.7.1-py2.7-macosx-10.6-x86_64.egg/cylp/py/modeling/CyLPModel.py:516: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if self.lower == None:
Setting up the LP model
Solving LP......
DONE!!
Single_Year_Stage_II.py:158: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  model = CyClpSimplex(LP)

In [5]:
z[:,2] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2010', tol = 0.24)


Preparing coefficient matrix...
('Preparing targets for ', '2010')
('Targets for year ', '2010', ' is ', CyLPArray([ -7.63177093e+05,  -7.43546219e+05,   4.10214815e+05,
         6.27348634e+05,   1.74941009e+06,   7.95463371e+09,
         3.53199726e+09,   3.23026426e+09,   2.92840048e+09,
         2.38059862e+10,   5.65358795e+10,   2.63560685e+10,
         3.20615128e+10,   5.72990259e+09,   1.79705612e+09,
         3.02143439e+08,  -6.40247904e+09,   9.29548536e+09,
         3.08932220e+09,   5.20121508e+09,   6.01147955e+08,
        -2.62295872e+10,   6.36406835e+09,   5.20937766e+10,
         3.65287607e+10,   3.47710135e+09,  -3.68857557e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [6]:
z[:,3] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2011', tol = 0.18)


Preparing coefficient matrix...
('Preparing targets for ', '2011')
('Targets for year ', '2011', ' is ', CyLPArray([  4.98571109e+05,  -1.90697774e+06,   1.78600258e+05,
         4.97789601e+05,   2.93082521e+05,   5.39574191e+09,
         9.50534581e+08,  -1.04226862e+08,   2.33476324e+09,
         1.87282075e+10,   3.88530715e+10,   1.97897837e+10,
         3.01091202e+10,   5.85709751e+09,   1.37999625e+09,
        -2.39723630e+09,  -9.10766089e+09,   3.65630475e+09,
        -1.11304682e+10,  -1.30551725e+10,  -1.97963350e+10,
        -5.98202559e+10,  -2.34907856e+10,   5.96125602e+10,
         7.75336020e+10,   1.75598616e+10,  -3.11926204e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [7]:
z[:,4] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2012', tol = 0.22)


Preparing coefficient matrix...
('Preparing targets for ', '2012')
('Targets for year ', '2012', ' is ', CyLPArray([ -4.36726260e+05,  -1.92443209e+06,  -4.18108816e+04,
         4.13631589e+04,  -1.00587874e+06,   2.77797886e+09,
        -1.57648504e+09,   1.69315575e+09,   2.51717023e+09,
         1.73388403e+10,   2.98830463e+10,   2.07527936e+10,
         3.07123535e+10,   6.10264598e+09,   1.67407730e+09,
        -4.07406968e+09,  -1.19188612e+10,  -7.64382253e+09,
        -2.46752657e+10,  -2.79367677e+10,  -3.21960019e+10,
        -8.56292495e+10,  -4.20085157e+10,   8.83017524e+10,
         1.08228851e+11,   3.80822804e+10,   3.89725452e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [8]:
z[:,5] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2013', tol = 0.27)


Preparing coefficient matrix...
('Preparing targets for ', '2013')
('Targets for year ', '2013', ' is ', CyLPArray([ -8.32453610e+05,  -2.43208271e+06,  -7.19943906e+04,
         4.23760722e+04,  -1.44265909e+06,   3.37926923e+08,
        -3.90685587e+09,   2.65834173e+09,   2.58122290e+09,
         1.56254773e+10,   2.11914108e+10,   2.06426531e+10,
         3.09403920e+10,   6.32929749e+09,   1.85002887e+09,
        -4.01517359e+09,  -1.15302272e+10,  -6.51091747e+09,
        -2.28554222e+10,  -2.58531452e+10,  -3.02195162e+10,
        -8.15697339e+10,  -3.83924316e+10,   9.63852555e+10,
         1.12254208e+11,   3.93936204e+10,   4.05599190e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [9]:
z[:,6] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2014', tol = 0.2)


Preparing coefficient matrix...
('Preparing targets for ', '2014')
('Targets for year ', '2014', ' is ', CyLPArray([ -1.11088847e+06,  -2.80064529e+06,  -9.54194050e+04,
         4.38530357e+04,  -2.85060057e+06,  -3.22950648e+09,
        -7.46192245e+09,   4.28776816e+08,   2.10870775e+09,
         1.02286217e+10,   1.07866127e+10,   1.49669191e+10,
         2.93140119e+10,   6.51864647e+09,   1.59621487e+09,
        -4.19139742e+09,  -1.21790055e+10,  -8.02669999e+09,
        -2.50123685e+10,  -2.81764958e+10,  -3.25194669e+10,
        -8.73355141e+10,  -4.31023948e+10,   8.94067598e+10,
         1.09403686e+11,   3.85259637e+10,   3.88120533e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [10]:
z[:,7] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2015', tol = 0.24)


Preparing coefficient matrix...
('Preparing targets for ', '2015')
('Targets for year ', '2015', ' is ', CyLPArray([ -1.38490699e+06,  -3.16833644e+06,  -1.16837456e+05,
         4.59696495e+04,  -4.23532853e+06,  -7.01472440e+09,
        -1.11978280e+10,  -2.10301335e+09,   1.59167367e+09,
         4.41064514e+09,  -5.01481225e+07,   8.71720953e+09,
         2.75314310e+10,   6.74782368e+09,   1.30787911e+09,
        -4.39064343e+09,  -1.29230018e+10,  -9.77484216e+09,
        -2.75167244e+10,  -3.08824087e+10,  -3.51935850e+10,
        -9.39821695e+10,  -4.85448915e+10,   8.12008326e+10,
         1.06021647e+11,   3.74921245e+10,   3.67891830e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [11]:
z[:,8] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2016', tol = 0.25)


Preparing coefficient matrix...
('Preparing targets for ', '2016')
('Targets for year ', '2016', ' is ', CyLPArray([ -1.62365517e+06,  -3.49607849e+06,  -1.35210495e+05,
         4.52399363e+04,  -5.82625598e+06,  -1.11044419e+10,
        -1.52900576e+10,  -5.49221679e+09,   9.16227939e+08,
        -2.42327704e+09,  -1.14335542e+10,   9.28223299e+08,
         2.52124334e+10,   6.98512180e+09,   8.99071554e+08,
        -4.65715814e+09,  -1.39615397e+10,  -1.22678380e+10,
        -3.11427697e+10,  -3.48312540e+10,  -3.90754733e+10,
        -1.03409018e+11,  -5.63337985e+10,   6.88039197e+10,
         1.00747409e+11,   3.58598772e+10,   3.38431076e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [12]:
z[:,9] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2017', tol = 0.28)


Preparing coefficient matrix...
('Preparing targets for ', '2017')
('Targets for year ', '2017', ' is ', CyLPArray([ -1.85340619e+06,  -3.81474504e+06,  -1.52893415e+05,
         4.80760840e+04,  -7.54384224e+06,  -1.55177744e+10,
        -1.96757004e+10,  -9.42488568e+09,   1.57731716e+08,
        -9.95303238e+09,  -2.33549246e+10,  -7.81773007e+09,
         2.26032681e+10,   7.19870071e+09,   4.22346372e+08,
        -4.96279329e+09,  -1.51693506e+10,  -1.51922041e+10,
        -3.54101105e+10,  -3.94883765e+10,  -4.36453194e+10,
        -1.14430883e+11,  -6.54736787e+10,   5.39869484e+10,
         9.43679528e+10,   3.38779371e+10,   3.03508280e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [13]:
z[:,10] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2018', tol = 0.3)


Preparing coefficient matrix...
('Preparing targets for ', '2018')
('Targets for year ', '2018', ' is ', CyLPArray([ -2.12194470e+06,  -4.17912531e+06,  -1.74808513e+05,
         5.04877933e+04,  -9.12391016e+06,  -1.99915510e+10,
        -2.41313505e+10,  -1.30891681e+10,  -5.64492779e+08,
        -1.73798249e+10,  -3.57670628e+10,  -1.62185412e+10,
         2.01270827e+10,   7.45546418e+09,  -1.81832120e+07,
        -5.24720924e+09,  -1.62789233e+10,  -1.78710456e+10,
        -3.92925490e+10,  -4.37141730e+10,  -4.77963575e+10,
        -1.24514796e+11,  -7.38266583e+10,   4.05900997e+10,
         8.86154728e+10,   3.20946218e+10,   2.71472544e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [14]:
z[:,11] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2019', tol = 0.4)


Preparing coefficient matrix...
('Preparing targets for ', '2019')
('Targets for year ', '2019', ' is ', CyLPArray([ -2.43160512e+06,  -4.59420505e+06,  -1.99351133e+05,
         5.15040313e+04,  -1.05018134e+07,  -2.44392827e+10,
        -2.85107414e+10,  -1.61762430e+10,  -1.19581121e+09,
        -2.43325507e+10,  -4.84240073e+10,  -2.37904856e+10,
         1.79385546e+10,   7.69552928e+09,  -3.77517668e+08,
        -5.48680283e+09,  -1.71851119e+10,  -2.00280894e+10,
        -4.23821715e+10,  -4.70576385e+10,  -5.10925218e+10,
        -1.32658055e+11,  -8.05324056e+10,   3.02198887e+10,
         8.42476445e+10,   3.07511950e+10,   2.45985841e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [15]:
z[:,12] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2020', tol = 0.4)


Preparing coefficient matrix...
('Preparing targets for ', '2020')
('Targets for year ', '2020', ' is ', CyLPArray([ -2.77958019e+06,  -5.05794245e+06,  -2.25643579e+05,
         5.29747112e+04,  -1.17900632e+07,  -2.89154301e+10,
        -3.29635039e+10,  -1.88671599e+10,  -1.77558229e+09,
        -3.10442106e+10,  -6.15869821e+10,  -3.07664791e+10,
         1.59119931e+10,   7.97867001e+09,  -6.85241215e+08,
        -5.69629923e+09,  -1.79531020e+10,  -2.18392649e+10,
        -4.49325520e+10,  -4.97977451e+10,  -5.38027551e+10,
        -1.39484066e+11,  -8.61322579e+10,   2.18418771e+10,
         8.07617999e+10,   2.96870933e+10,   2.24595054e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [16]:
z[:,13] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2021', tol = 0.35)


Preparing coefficient matrix...
('Preparing targets for ', '2021')
('Targets for year ', '2021', ' is ', CyLPArray([ -3.12230591e+06,  -5.51236373e+06,  -2.53271435e+05,
         5.55524583e+04,  -1.30195028e+07,  -3.33570063e+10,
        -3.73535685e+10,  -2.16298196e+10,  -2.35448410e+09,
        -3.77284133e+10,  -7.45414604e+10,  -3.77757973e+10,
         1.38753572e+10,   8.22985038e+09,  -9.98578524e+08,
        -5.90986837e+09,  -1.87413019e+10,  -2.37004291e+10,
        -4.75647681e+10,  -5.26306418e+10,  -5.66029801e+10,
        -1.46505703e+11,  -9.18953594e+10,   1.31647460e+10,
         7.71466587e+10,   2.85819244e+10,   2.02649775e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [17]:
z[:,14] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2022', tol = 0.25)


Preparing coefficient matrix...
('Preparing targets for ', '2022')
('Targets for year ', '2022', ' is ', CyLPArray([ -3.48917965e+06,  -5.99827988e+06,  -2.81942348e+05,
         5.62267775e+04,  -1.40767842e+07,  -3.79856162e+10,
        -4.19088985e+10,  -2.42994855e+10,  -2.93427751e+09,
        -4.45309786e+10,  -8.80841059e+10,  -4.48127483e+10,
         1.18608937e+10,   8.51660116e+09,  -1.29849386e+09,
        -6.11534165e+09,  -1.94884243e+10,  -2.54595869e+10,
        -5.00287500e+10,  -5.52723051e+10,  -5.92179342e+10,
        -1.53127632e+11,  -9.73244371e+10,   5.10651415e+09,
         7.37998626e+10,   2.75621440e+10,   1.81834542e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [21]:
z[:,15] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2023', tol = 0.23)


Preparing coefficient matrix...
('Preparing targets for ', '2023')
('Targets for year ', '2023', ' is ', CyLPArray([ -3.84516314e+06,  -6.47161328e+06,  -3.09071141e+05,
         5.89843940e+04,  -1.51598995e+07,  -4.25444893e+10,
        -4.64279733e+10,  -2.70232185e+10,  -3.51690975e+09,
        -5.13486796e+10,  -1.01489597e+11,  -5.18693057e+10,
         9.81875626e+09,   8.77423621e+09,  -1.60191266e+09,
        -6.32564280e+09,  -2.02592656e+10,  -2.72834633e+10,
        -5.25903665e+10,  -5.80230689e+10,  -6.19376273e+10,
        -1.59982199e+11,  -1.02956052e+11,  -3.35568022e+09,
         7.02574612e+10,   2.64795077e+10,   1.60135610e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [22]:
z[:,16] = Single_Year_Stage_II(puf, Stage_I_factors, Stage_II_targets, year = '2024', tol = 0.33)


Preparing coefficient matrix...
('Preparing targets for ', '2024')
('Targets for year ', '2024', ' is ', CyLPArray([ -4.19160979e+06,  -6.93145319e+06,  -3.36369548e+05,
         6.04827157e+04,  -1.62951849e+07,  -4.70167916e+10,
        -5.08463804e+10,  -2.97465532e+10,  -4.09868777e+09,
        -5.80722660e+10,  -1.14573303e+11,  -5.89196832e+10,
         7.78801564e+09,   9.02755988e+09,  -1.91577448e+09,
        -6.53614284e+09,  -2.10335941e+10,  -2.91128401e+10,
        -5.51699172e+10,  -6.07965094e+10,  -6.46795458e+10,
        -1.66873819e+11,  -1.08614019e+11,  -1.18613086e+10,
         6.67086065e+10,   2.53949174e+10,   1.38493505e+10]))
Adding constraints
Setting up the LP model
Solving LP......
DONE!!

In [23]:
z = df(z, columns=['WT2008','WT2009','WT2010','WT2011','WT2012','WT2013','WT2014',
                   'WT2015','WT2016','WT2017','WT2018','WT2019','WT2020','WT2021',
                   'WT2022','WT2023','WT2024'])
z.to_csv('WEIGHTS.csv', index = False)

In [ ]: