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

Inconsistent indexing for initial variable bounds #192

Open
emunsing opened this issue Nov 17, 2023 · 1 comment
Open

Inconsistent indexing for initial variable bounds #192

emunsing opened this issue Nov 17, 2023 · 1 comment

Comments

@emunsing
Copy link

emunsing commented Nov 17, 2023

It appears that the s.variables[i].toInd value is computed differently for the first variable created (i==0) than it is treated for variable created later.

The indexing for the i=0 variable goes from fromInd==0 to toInd==len(var)-1, while for a subsequent variable where the indexing goes from fromInd=j to toind==j + len(var)

Example:

import numpy as np
from cylp.cy import CyClpSimplex

s = CyClpSimplex()
x = s.addVariable('x', 3)
y = s.addVariable('y', 2)
s += 1 <= x <= 2
s += 3 <= y <= 4

print(s.variablesLower[s.variables[0].fromInd: s.variables[0].toInd])
print(s.variablesLower[s.variables[1].fromInd: s.variables[1].toInd])

[Out:] 
[1. 1.]
[3. 3.]

Even more succinctly, this behavior is immediately visible on initializing the initial variable:

s = CyClpSimplex()
x = s.addVariable('x', 3)
print(s.variablesLower[s.variables[0].fromInd: s.variables[0].toInd])

I would expect there to be three entries for the bounds on x.

@emunsing
Copy link
Author

A workaround that appears to be robust is to index using the variable dim:

[s.variables[0].fromInd: s.variables[0].fromInd + s.variables[0].dim]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant