Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding JPOF Contrib Package #2762

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions pyomo/contrib/jpof/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2022
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.contrib.jpof.jpof_writer import JPOFWriter

29 changes: 29 additions & 0 deletions pyomo/contrib/jpof/example/dsrosen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pyomo.environ as pe
import pyomo.contrib.jpof

def create(N):
M = pe.ConcreteModel()

def x_init(model, i):
if i % 2 == 1:
return -1.2
else:
return 1.2

M.x = pe.Var(pe.RangeSet(1,N), initialize=x_init)
M.p = pe.Param(initialize=0, mutable=True)
M.I = pe.RangeSet(1,N-1)

M.f = pe.Objective(expr=sum( 100*(M.x[i+1]-M.x[i]**2+M.p)**2 + (1-M.x[i])**2 for i in M.I))

return M

writer = pyomo.contrib.jpof.JPOFWriter()

M = create(3)
writer(M, filename="dsrosen3.jpof", io_options={'file_determinism':3, 'symbolic_solver_labels':True})
M = create(6)
writer(M, filename="dsrosen6.jpof", io_options={'file_determinism':3, 'symbolic_solver_labels':True})
M = create(10)
writer(M, filename="dsrosen10.jpof", io_options={'file_determinism':3, 'symbolic_solver_labels':True})

106 changes: 106 additions & 0 deletions pyomo/contrib/jpof/example/dsrosen10.jpof
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"__metadata__": {
"version": 20210301,
"format": "JSON Parameterized Optimization Format (JPOF)"
},
"model": {
"config": {
"symbolic_solver_labels": 1,
"skip_trivial_constraints": 0,
"file_determinism": 3,
"include_all_variable_bounds": 0
},
"obj": [
{
"expr": "sum,18,*,N,100,pow,sum,3,V,1,neg,pow,V,0,N,2,P,0,N,2,pow,+,*,N,-1,V,0,N,1,N,2,*,N,100,pow,sum,3,V,2,neg,pow,V,1,N,2,P,0,N,2,pow,+,*,N,-1,V,1,N,1,N,2,*,N,100,pow,sum,3,V,3,neg,pow,V,2,N,2,P,0,N,2,pow,+,*,N,-1,V,2,N,1,N,2,*,N,100,pow,sum,3,V,4,neg,pow,V,3,N,2,P,0,N,2,pow,+,*,N,-1,V,3,N,1,N,2,*,N,100,pow,sum,3,V,5,neg,pow,V,4,N,2,P,0,N,2,pow,+,*,N,-1,V,4,N,1,N,2,*,N,100,pow,sum,3,V,6,neg,pow,V,5,N,2,P,0,N,2,pow,+,*,N,-1,V,5,N,1,N,2,*,N,100,pow,sum,3,V,7,neg,pow,V,6,N,2,P,0,N,2,pow,+,*,N,-1,V,6,N,1,N,2,*,N,100,pow,sum,3,V,8,neg,pow,V,7,N,2,P,0,N,2,pow,+,*,N,-1,V,7,N,1,N,2,*,N,100,pow,sum,3,V,9,neg,pow,V,8,N,2,P,0,N,2,pow,+,*,N,-1,V,8,N,1,N,2",
"sense": "min",
"label": "f"
}
],
"con": [],
"var": [
{
"label": "x[1]",
"id": 0,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[2]",
"id": 1,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[3]",
"id": 2,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[4]",
"id": 3,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[5]",
"id": 4,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[6]",
"id": 5,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[7]",
"id": 6,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[8]",
"id": 7,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[9]",
"id": 8,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[10]",
"id": 9,
"value": 1.2,
"type": "R",
"fixed": 0
}
],
"param": [
{
"label": "p",
"id": 0,
"value": 0
}
],
"set": {},
"indexed_vars": [
"x"
],
"indexed_params": []
}
}
57 changes: 57 additions & 0 deletions pyomo/contrib/jpof/example/dsrosen3.jpof
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"__metadata__": {
"version": 20210301,
"format": "JSON Parameterized Optimization Format (JPOF)"
},
"model": {
"config": {
"symbolic_solver_labels": 1,
"skip_trivial_constraints": 0,
"file_determinism": 3,
"include_all_variable_bounds": 0
},
"obj": [
{
"expr": "sum,4,*,N,100,pow,sum,3,V,1,neg,pow,V,0,N,2,P,0,N,2,pow,+,*,N,-1,V,0,N,1,N,2,*,N,100,pow,sum,3,V,2,neg,pow,V,1,N,2,P,0,N,2,pow,+,*,N,-1,V,1,N,1,N,2",
"sense": "min",
"label": "f"
}
],
"con": [],
"var": [
{
"label": "x[1]",
"id": 0,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[2]",
"id": 1,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[3]",
"id": 2,
"value": -1.2,
"type": "R",
"fixed": 0
}
],
"param": [
{
"label": "p",
"id": 0,
"value": 0
}
],
"set": {},
"indexed_vars": [
"x"
],
"indexed_params": []
}
}
78 changes: 78 additions & 0 deletions pyomo/contrib/jpof/example/dsrosen6.jpof
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"__metadata__": {
"version": 20210301,
"format": "JSON Parameterized Optimization Format (JPOF)"
},
"model": {
"config": {
"symbolic_solver_labels": 1,
"skip_trivial_constraints": 0,
"file_determinism": 3,
"include_all_variable_bounds": 0
},
"obj": [
{
"expr": "sum,10,*,N,100,pow,sum,3,V,1,neg,pow,V,0,N,2,P,0,N,2,pow,+,*,N,-1,V,0,N,1,N,2,*,N,100,pow,sum,3,V,2,neg,pow,V,1,N,2,P,0,N,2,pow,+,*,N,-1,V,1,N,1,N,2,*,N,100,pow,sum,3,V,3,neg,pow,V,2,N,2,P,0,N,2,pow,+,*,N,-1,V,2,N,1,N,2,*,N,100,pow,sum,3,V,4,neg,pow,V,3,N,2,P,0,N,2,pow,+,*,N,-1,V,3,N,1,N,2,*,N,100,pow,sum,3,V,5,neg,pow,V,4,N,2,P,0,N,2,pow,+,*,N,-1,V,4,N,1,N,2",
"sense": "min",
"label": "f"
}
],
"con": [],
"var": [
{
"label": "x[1]",
"id": 0,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[2]",
"id": 1,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[3]",
"id": 2,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[4]",
"id": 3,
"value": 1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[5]",
"id": 4,
"value": -1.2,
"type": "R",
"fixed": 0
},
{
"label": "x[6]",
"id": 5,
"value": 1.2,
"type": "R",
"fixed": 0
}
],
"param": [
{
"label": "p",
"id": 0,
"value": 0
}
],
"set": {},
"indexed_vars": [
"x"
],
"indexed_params": []
}
}