Skip to content

Commit

Permalink
Bug fixed: to_lp, cpt_solver, and soc_solve.
Browse files Browse the repository at this point in the history
  • Loading branch information
XiongPengNUS committed Jan 19, 2024
1 parent 3481cf4 commit 552f009
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 137 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="https://github.com/XiongPengNUS/rsome/blob/master/rsologo.png?raw=true" width=100>
<img src="https://github.com/XiongPengNUS/rsome/blob/master/rsologo.png?raw=true" width=200>

# Robust Stochastic Optimization Made Easy

Expand All @@ -13,7 +13,7 @@
![GitHub issues](https://img.shields.io/github/issues-raw/XiongPengNUS/rsome)

- Website: [RSOME for Python](https://xiongpengnus.github.io/rsome/)
- PyPI: [RSOME 1.2.5](https://pypi.org/project/rsome/)
- PyPI: [RSOME 1.2.6](https://pypi.org/project/rsome/)

RSOME (Robust Stochastic Optimization Made Easy) is an open-source Python package for generic modeling of optimization problems (subject to uncertainty). Models in RSOME are constructed by variables, constraints, and expressions that are formatted as N-dimensional arrays. These arrays are consistent with the NumPy library in terms of syntax and operations, including broadcasting, indexing, slicing, element-wise operations, and matrix calculation rules, among others. In short, RSOME provides a convenient platform to facilitate developments of robust optimization models and their applications.

Expand Down
18 changes: 12 additions & 6 deletions rsome/cpt_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def solve(form, display=True, log=False, params={}):

try:
if xmat:
warnings.warn('The SOCP solver ignores exponential cone constraints. ')
# if lmi:
# warnings.warn('The SOCP solver ignores semidefinite cone constraints. ')
warnings.warn('The conic solver ignores exponential cone constraints. ')
except AttributeError:
pass

Expand All @@ -52,14 +50,15 @@ def solve(form, display=True, log=False, params={}):
linear_ineq = form.linear[~is_eq]
linear_eq = form.linear[is_eq]
num_ineq = linear_ineq.shape[0]
# num_eq = linear_eq.shape[0]

const_ineq = form.const[~is_eq]
const_eq = form.const[is_eq]

num_constr, num_var = form.linear.shape

env = cp.Envr()
envconfig = cp.EnvrConfig()
envconfig.set('nobanner', '1')
env = cp.Envr(envconfig)
m = env.createModel()
m.setParam(cp.COPT.Param.Logging, log)
m.setParam(cp.COPT.Param.LogToConsole, False)
Expand Down Expand Up @@ -149,7 +148,14 @@ def solve(form, display=True, log=False, params={}):
else:
y = None

solution = Solution('COPT', objval, x_sol, status, stime, y=y)
xx_sol = np.zeros(len(form.vtype))
xx_sol[idx_cont] = x_sol[:len(idx_cont)]
if idx_bin:
xx_sol[idx_bin] = x_sol[len(idx_cont): len(idx_cont)+len(idx_bin)]
if idx_int:
xx_sol[idx_int] = x_sol[len(idx_cont)+len(idx_bin):]

solution = Solution('COPT', objval, xx_sol, status, stime, y=y)
except cp.CoptError:
warnings.warn('Fail to find the optimal solution.')
# solution = None
Expand Down
4 changes: 3 additions & 1 deletion rsome/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def to_socp(self, degree=4, cuts=(-30, 60)):

left_width = self.linear.shape[1]
qmat = self.qmat
lmi = self.lmi

linear = self.linear
const = self.const
Expand Down Expand Up @@ -570,4 +571,5 @@ def to_socp(self, degree=4, cuts=(-30, 60)):
qmat += [list(left_width + num_vars + np.array([2, 1, 0]) + q*3)
for q in range(3+degree)]

return SOCProg(linear, const, sense, vtype, ub, lb, qmat, obj)
# return SOCProg(linear, const, sense, vtype, ub, lb, qmat, obj)
return GCProg(linear, const, sense, vtype, ub, lb, qmat, [], lmi, obj)
Loading

0 comments on commit 552f009

Please sign in to comment.