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

remove all_vars from argument of convert_all and decode_solution #7

Merged
merged 1 commit into from
Aug 20, 2022
Merged

remove all_vars from argument of convert_all and decode_solution #7

merged 1 commit into from
Aug 20, 2022

Conversation

nariaki3551
Copy link
Contributor

@nariaki3551 nariaki3551 commented Aug 17, 2022

As per title, this change removed all_vars from the argument of convert_all and decode_solution functions.
I think that it is more useful for users not to have to provide all_vars, a list of dict variables, to these functions.

I have tested this pull request by pytest and the following code.

import pulp as pl
import numpy as np

# Variables * must be defined as dictionaries
x = {
    i: pl.LpVariable("x_{}".format(i), cat=pl.LpInteger)
    for i in range(2)
}

problem = pl.LpProblem()
problem += x[0] + x[1]
problem += x[0] + x[1] >= 2

import pulp2mat
from scipy.optimize import milp
c, integrality, constraints, bounds = pulp2mat.convert_all(problem)
result = milp(c, integrality=integrality, constraints=constraints, bounds=bounds)

pulp2mat.decode_solution(result, problem)
print("x[0] =", x[0].value())
print("x[1] =", x[1].value())

@rtonoue rtonoue merged commit bb376a8 into rtonoue:main Aug 20, 2022
@rtonoue
Copy link
Owner

rtonoue commented Aug 20, 2022

@nariaki3551,

Thank you! Getting variable properties from pulp.LpProblem seems to be more straightforward.
I will modify some comments and the readme accordingly to this change.

@nariaki3551
Copy link
Contributor Author

Thanks for your review and merge!

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

Successfully merging this pull request may close these issues.

None yet

2 participants