예제 #1
0
 def test_ef_solve_with_csvwriter(self):
     """ solve the ef and report gap"""
     stsolver = rapper.StochSolver("ReferenceModel.py",
                                   fsfct="pysp_instance_creation_callback",
                                   tree_model=self.farmer_concrete_tree)
     res, gap = stsolver.solve_ef(solvername, tee=True, need_gap=True)
     csvw.write_csv_soln(stsolver.scenario_tree, "testcref")
     with open("testcref.csv", 'r') as f:
         line = f.readline()
     assert (line.split(",")[0] == "FirstStage")
예제 #2
0
 def test_NetX_ef_csvwriter(self):
     """ solve the ef and report gap"""
     import NetXReferenceModel as ref
     tree_model = ref.pysp_scenario_tree_model_callback()
     stsolver = rapper.StochSolver("NetXReferenceModel.py",
                                   fsfct="pysp_instance_creation_callback",
                                   tree_model=tree_model)
     res, gap = stsolver.solve_ef(solvername, tee=True, need_gap=True)
     csvw.write_csv_soln(stsolver.scenario_tree, "testcref")
     with open("testcref_StageCostDetail.csv", 'r') as f:
         line = f.readline()
     assert (line.split(",")[0] == "Stage1")
예제 #3
0
#       want to delete a few files before you run.
import os
import pyomo.pysp.plugins.csvsolutionwriter as csvw
import basicclasses as bc
import distr2pysp as dp
import stoch_solver as st

# concrete as needed by IDAES (serial):
print("\n*** 2Stage_json")
tree_model = bc.Tree_2Stage_json_dir('concrete_farmer',
                                     'TreeTemplateFile.json')

stsolver = st.StochSolver('cref.py', tree_model)
stsolver.solve_ef('cplex')
# the stsolver.scenario_tree has the solution
csvw.write_csv_soln(stsolver.scenario_tree, "testcref")

### simple tests ####
print("\n*** 2Stage_AMPL")
bc.do_2Stage_AMPL_dir('farmer', 'TreeTemplateFile.dat', 'ScenTemplate.dat')
os.system('runef -m farmer/ReferenceModel.py -s farmer')

print("\n*** 2Stage_AMPL again")
bc.do_2Stage_AMPL_dir('farmer', 'TreeTemplateFile.dat', \
                      'scen_template_with_tokens.dat', \
                      '#STARTSCEN', '#ENDSCEN')
os.system('runef -m farmer/ReferenceModel.py -s farmer')

#==== distrs ====
print("\n*** indep norms")
dp.indep_norms_from_data_2stage('concrete_farmer/dptest/datafiledict.json',
예제 #4
0
파일: demodaps.py 프로젝트: pazochoa/pyomo
import os
import json
import pyomo.pysp.plugins.csvsolutionwriter as csvw
import basicclasses as bc
import distr2pysp as dp
import stoch_solver as st

# concrete as needed by IDAES (serial):
print("\n*** 2Stage_json")
tree_model = bc.Tree_2Stage_json_dir('concrete_farmer',
                                     'TreeTemplateFile.json')

stsolver = st.StochSolver('cref.py', tree_model)
stsolver.solve_ef('cplex')
# the stsolver.scenario_tree has the solution
csvw.write_csv_soln(stsolver.scenario_tree, "testcref")

# do it again with PH
sopts = {}
sopts['threads'] = 2
phopts = {}
phopts['--output-solver-log'] = None
phopts['--max-iterations'] = '3'
stsolver = st.StochSolver('cref.py', tree_model, phopts)
stsolver.solve_ph(subsolver='cplex', default_rho=1, phopts=phopts, sopts=sopts)
csvw.write_csv_soln(stsolver.scenario_tree, "testph")

# do it one more time with ph parms from json file
with open('phopts.json') as infile:
    phopts = json.load(infile)
stsolverII = st.StochSolver('cref.py', tree_model, phopts)