-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add pyoptinterface_based_impl.py and integrate it #104
Conversation
b2b4273
to
3209603
Compare
Speed up of
|
for i in range(n): | |
# Set the ith row of the A matrix as the objective function | |
objective_function = A[ | |
i, | |
] |
Noticing that only the objective function changes after each iteration, optimization can be achieved.
remove_redundant_facets()
The outer loop is a while loop, and the inner loop is a for loop. We observe that throughout the for loop,
Aeq_sparse
, beq
, A_sparse
, and [val]
remain unchanged. Within each iteration of the for loop, only lb[i]
, ub[i]
, and the objective function change. Between consecutive iterations of the for loop, only lb[i]
and ub[i]
from the previous iteration may be modified. Therefore, we can achieve fine-tuning by adjusting a single model throughout the entire for loop.dingo/dingo/gurobi_based_implementations.py
Lines 404 to 442 in 4a961e7
# Loop until nor redundant facets are found | |
while removed > 0 or offset > 0: | |
removed = 0 | |
offset = 0 | |
indices = indices_iter | |
indices_iter = [] | |
Aeq_sparse = sp.csr_matrix(Aeq_res) | |
beq = np.array(beq_res) | |
b_res = [] | |
A_res = np.empty((0, n), float) | |
for i in indices: | |
# Set the ith row of the A matrix as the objective function | |
objective_function = A[ | |
i, | |
] | |
redundant_facet_right = True | |
redundant_facet_left = True | |
# for the maximum | |
objective_function_max = np.asarray( | |
[-x for x in objective_function] | |
) | |
model_iter = update_model( | |
model_iter, | |
n, | |
Aeq_sparse, | |
beq, | |
lb, | |
ub, | |
A_sparse, | |
[val], | |
objective_function_max, | |
) | |
model_iter.optimize() |
Experiment (iAF1260 model)
dingo/pyoptInterface_based_impl.py
Outdated
# And check whether the computed radius is negative | ||
if r < 0: | ||
print( | ||
"The radius calculated has negative value. The polytope is infeasible or something went wrong with the solver" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please throw an exception here instead of printing a message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK.
dingo/pyoptInterface_based_impl.py
Outdated
# Reset the inequality | ||
# model_iter.set_variable_attribute(v[i], poi.VariableAttribute.LowerBound, lb[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What these lines stand for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code above will be more symmetrical, but in reality, it carries no meaning. I have removed it.
Thanks @KeShih! This is a great contribution! |
What?
pyoptinterface_based_impl.py
, which uses the PyOptInterface package.fast
andslow
modes, use a unified interface instead.set_default_solver(solver_name)
indingo.pyoptinterface_based_impl
module. Also, we can change the solver inMetabolicNetwork
andMetabolicNetwork
class by invoking the methodset_solver(self, solver)
How to test it?
Documentation
See #106.