-
Notifications
You must be signed in to change notification settings - Fork 517
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c30f338
commit 7459a82
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pyomo.environ as pe | ||
from pyomo.common import unittest | ||
from pyomo.common.dependencies import attempt_import | ||
nx, nx_available = attempt_import('networkx') | ||
plotly, plotly_available = attempt_import('plotly') | ||
|
||
|
||
@unittest.skipUnless(nx_available, 'plot_pyomo_model requires networkx') | ||
@unittest.skipUnless(plotly_available, 'plot_pyomo_model requires plotly') | ||
class TestPlotPyomoModel(unittest.TestCase): | ||
def test_plot_pyomo_model(self): | ||
""" | ||
Unfortunately, this test only ensures the code runs without errors. | ||
It does not test for correctness. | ||
""" | ||
m = pe.ConcreteModel() | ||
m.x = pe.Var(bounds=(-1, 1)) | ||
m.y = pe.Var() | ||
m.z = pe.Var() | ||
m.obj = pe.Objective(expr=m.y**2 + m.z**2) | ||
m.c1 = pe.Constraint(expr=m.y == 2*m.x + 1) | ||
m.c2 = pe.Constraint(expr=m.z >= m.x) | ||
from pyomo.util.graph import plot_pyomo_model | ||
plot_pyomo_model(m, plot_title='test plot', bipartite_plot=False, show_plot=False) | ||
plot_pyomo_model(m, plot_title='test plot', bipartite_plot=True, show_plot=False) | ||
|