Skip to content

Commit

Permalink
updating dcopf and copper plate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbynum committed May 23, 2019
1 parent e36df83 commit 8145016
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
6 changes: 3 additions & 3 deletions egret/models/tests/test_acopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_acopf_model(self, test_case, soln_case):
md, results = solve_acopf(md_dict, "ipopt", acopf_model_generator=acopf_model, solver_tee=False, return_results=True)

self.assertTrue(results.solver.termination_condition == TerminationCondition.optimal)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e04)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e-4)
self.assertTrue(comparison)


Expand All @@ -73,7 +73,7 @@ def test_acopf_model(self, test_case, soln_case):
md, results = solve_acopf(md_dict, "ipopt", acopf_model_generator=acopf_model, solver_tee=False, return_results=True)

self.assertTrue(results.solver.termination_condition == TerminationCondition.optimal)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e04)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e-4)
self.assertTrue(comparison)


Expand All @@ -99,7 +99,7 @@ def test_acopf_model(self, test_case, soln_case):
md, results = solve_acopf(md_dict, "ipopt", acopf_model_generator=acopf_model, solver_tee=False, return_results=True)

self.assertTrue(results.solver.termination_condition == TerminationCondition.optimal)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e04)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e-4)
self.assertTrue(comparison)


Expand Down
18 changes: 13 additions & 5 deletions egret/models/tests/test_copperplate_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,35 @@
from egret.models.copperplate_dispatch import *
from egret.data.model_data import ModelData
from parameterized import parameterized
from egret.parsers.matpower_parser import create_ModelData

current_dir = os.path.dirname(os.path.abspath(__file__))
case_names = ['pglib_opf_case3_lmbd','pglib_opf_case30_ieee','pglib_opf_case300_ieee']#,'pglib_opf_case3012wp_k','pglib_opf_case13659_pegase']
test_cases = [os.path.join(current_dir, 'transmission_test_instances', '{}.json'.format(i)) for i in case_names]
test_cases = [os.path.join(current_dir, 'transmission_test_instances', 'pglib-opf-master', '{}.m'.format(i)) for i in case_names]
soln_cases = [os.path.join(current_dir, 'transmission_test_instances', 'dcopf_solution_files', '{}_dcopf_solution.json'.format(i)) for i in case_names]

class TestCopperPlateDispatch(unittest.TestCase):
show_output = True

@classmethod
def setUpClass(self):
download_dir = os.path.join(current_dir, 'transmission_test_instances')
if not os.path.exists(os.path.join(download_dir, 'pglib-opf-master')):
from egret.thirdparty.get_pglib import get_pglib
get_pglib(download_dir)

@parameterized.expand(zip(test_cases, soln_cases))
def test_copperplate_dispatch_model(self, test_case, soln_case):
md_soln = ModelData()
md_soln.read_from_json(soln_case)

md_dict = ModelData()
md_dict.read_from_json(test_case)
md_dict = create_ModelData(test_case)

md, results = solve_copperplate_dispatch(md_dict, "gurobi", solver_tee=False, return_results=True)
md, results = solve_copperplate_dispatch(md_dict, "ipopt", solver_tee=False, return_results=True)

self.assertTrue(results.solver.termination_condition == TerminationCondition.optimal)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e04)
print(md_soln.data['system']['total_cost'], md.data['system']['total_cost'])
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e-4)
self.assertTrue(comparison)


Expand Down
19 changes: 13 additions & 6 deletions egret/models/tests/test_dcopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,38 @@
from egret.models.dcopf import *
from egret.data.model_data import ModelData
from parameterized import parameterized
from egret.parsers.matpower_parser import create_ModelData

current_dir = os.path.dirname(os.path.abspath(__file__))
case_names = ['pglib_opf_case3_lmbd','pglib_opf_case30_ieee','pglib_opf_case300_ieee']#,'pglib_opf_case3012wp_k','pglib_opf_case13659_pegase']
test_cases = [os.path.join(current_dir, 'transmission_test_instances', '{}.json'.format(i)) for i in case_names]
test_cases = [os.path.join(current_dir, 'transmission_test_instances', 'pglib-opf-master', '{}.m'.format(i)) for i in case_names]
soln_cases = [os.path.join(current_dir, 'transmission_test_instances', 'dcopf_solution_files', '{}_dcopf_solution.json'.format(i)) for i in case_names]

class TestBThetaDCOPF(unittest.TestCase):
show_output = True

@classmethod
def setUpClass(self):
download_dir = os.path.join(current_dir, 'transmission_test_instances')
if not os.path.exists(os.path.join(download_dir, 'pglib-opf-master')):
from egret.thirdparty.get_pglib import get_pglib
get_pglib(download_dir)

@parameterized.expand(zip(test_cases, soln_cases))
def test_btheta_dcopf_model(self, test_case, soln_case):
dcopf_model = create_btheta_dcopf_model

md_soln = ModelData()
md_soln.read_from_json(soln_case)

md_dict = ModelData()
md_dict.read_from_json(test_case)
md_dict = create_ModelData(test_case)

md, results = solve_dcopf(md_dict, "gurobi", dcopf_model_generator=dcopf_model, solver_tee=False, return_results=True)
md, results = solve_dcopf(md_dict, "ipopt", dcopf_model_generator=dcopf_model, solver_tee=False, return_results=True)

self.assertTrue(results.solver.termination_condition == TerminationCondition.optimal)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e04)
comparison = math.isclose(md.data['system']['total_cost'], md_soln.data['system']['total_cost'], rel_tol=1e-4)
self.assertTrue(comparison)


if __name__ == '__main__':
unittest.main()
unittest.main()

0 comments on commit 8145016

Please sign in to comment.