I want to know whether cvxpy can only implement this form of quadratic programming (just one formulation):
objective = cp.Minimize(cp.sum_squares(A # x - b))
This is the link in cvxpy to implement Mixed-integer quadratic program:
https://www.cvxpy.org/examples/basic/mixed_integer_quadratic_program.html
If I want to solve an objective function of the sum form:
Whether I can use a nested for loop to implement it? But I don't know how to do and I can not find the API to implement it. I used to implement Linear programming using Python library PULP, and it can use for loop to define the objective function and the constraints. Can i do this in cvxpy library?
Is my expression clear? If you need more information, just contact me. Thank you!
Related
I am using PySCIPOpt and have a MIP with some quadratic constraints (works). Now, I want to implement a Primal Heuristic (should run once before presolving), that fixes certain Variables and optimizes afterwards.
Ìn pseudo-code something like:
For x in ToFIX:
model.fixVar(x, my_guess(x))
model.optimize()
*Any found solution is used as solution of the original problem*
For x in ToFIX:
model.unFixVar(x)
I worked around that problem by creating a second model, solving that, identifying the variables by their name and using model.trySol().
This mostly works but is slow and certainly not the way it is meant to be implemented.
Any hint, which functionalities to use is appreciated.
sorry this took a while to answer.
What you want to implement is a sub-scip heuristic. This is certainly possible, but if you want to do it in PySCIPOpt you might have to wrap some missing methods from the C-API.
I suggest you take a look at heur_rens.c in the SCIP code. The methods you would need to wrap are probably SCIPcopyLargeNeighborhoodSearch and SCIPtranslateSubSol which should save you a lot of trouble. Please refer to the section extending the interface in the PySCIPopt Readme.
I am trying to compute the eigenvalues and eigenvectors of a potentially large and sparse non-symmetrical NxN matrix (N > 10^6). I would not need all of them, but maybe the first of them. Ideally, I'd like to do so from Java but could move to C, C++ or Python if required.
My matrix can potentially have both complex eigenvalues and eigenvectors. For example, see the results for this Wolfram Alpha sample.
I found several ways to do this using a number of Java libraries and wrote some evaluation code for them:
Commons-Math: EigenDecomposition
JAMA: EigenvalueDecomposition
MTJ: EVD
COLT: EigenvalueDecomposition
But the problem I am facing is that these libraries do not return (or at least I found no way to get) the complex valued eigenvectors. Most of them do return the complex valued eigenvalues, but not complex eigenvectors. They typically provide the latter in the form of a "vector of reals" or "real matrix" having columns as each eigenvector.
I do as a matter of fact need the eigenvalues in complex form, if any.
Now, I recently started looking into Spectra (C++) which seems to support my use case. But would like to first ask and maybe discard a misunderstanding on my side or something I may have skipped from Java land because I'd like to keep using a single platform/language as far as it's possible.
Is there anything I should be looking into? Also, If I end up moving away from Java for this task, any other alternatives to Spectra I could be looking into? Thanks!
Just in case anyone stumbles upon this, I finally went the C++ way because none of the Java libraries provided the complex eigenvectors as I needed.
I have ended up implementing most of the stuff I need with C++ using Spectra and Eigen. Then I have built a series of native wrapper classes using SWIG.
For everyone in the future with the same question: there is a library for Java called Jeigen that can do this. It is actually a Java wrapper for the Eigen C++ library that the original poster already mentioned in his own answer.
You can find Jeigen here.
I am kind of new to the SCIP. I want to use SCIP as a branch and price framework. I have coded the problem in C++ already and also have implemented the pricer or column generation as a function. In fact I have implemented the BP algorithm for the root node by linking Cplex.dll to the project and now need to code the branching tree and decided to use SCIP for this purpose.
I want to know what is the fastest way I can solve my problem using SCIP and the old codes which I have? Or maybe using GCG is a better and faster way?
I have read the GCG documentation but doesn't understand if I should implement the pricer myself again or not? In fact I don't understand the difference between these two (SCIP and GCG).
Thanks.
In GCG, you do not need to implement anything yourself. It is a generic solver for branch-and-price. You have to provide the compact formulation, that is, a model which after applying a Dantzig-Wolfe reformulation leads to the master problem you are solving. The reformulation also provides a MIP-formulation of the pricing problem, so GCG can solve this as a sub-MIP for pricing. There is the possibility, however, to plug-in a pricing solver in GCG, to which the pricing MIP to be solved will be passed (with objective function corresponding to the current pricing round). The pricing solver can then solve this problem with any problem-specific algorithm and pass solutions back to GCG.
In SCIP, on the other hand, you create the master problem you want to solve and implement a pricer which gets dual values from the LP and solves the corresponding pricing problem. This is probably very similar to what you have already.
Additionally, if you want to do branch-and-price, you need a branching rule. GCG comes with some generic ones, in SCIP you would have to implement one yourself (since the branching decisions must be regarded within your pricing procedure).
Overall, SCIP is a framework for branch-and-price, i.e., it provides the tree management, LP solving and updates, etc., but you need to implement some things yourself like a reader, the pricer, and the branching rules. GCG is a generic solver, so you can just plug in a compact model, which is reformulated and solved in a generic way. The reformulation is either provided by you via an input file or you can try to let GCG detect an appropriate structure. You do not need to implement anything. It already provides some nice features like primal heuristics that make use of the reformulation, an automatic management of which pricing problem is solved when, and more. On the other hand, the possibilities to extend it further, e.g., by a pricing solver and branching rules are restricted compared to SCIP, since you have to stick to the structure defined by GCG.
I would say that using SCIP and adding your pricer is probably the easier way and more similar to what you already have (you do not need to formulate the compact model). If you already have an idea on how your branching should work, it should also not be too hard to implement within SCIP.
I am currently struggling to solve a system of linear equations using python. I have tried using numpy.linalg.solve, but it seems that this will only work for square arrays, which mine are not. Is there another function that I can use to solve my system that I don't know about, or is there some different method that I should try to implement here? Thanks in advance.
What about using the least squares method if you want to use numpy?
http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html .
But it probably won't give you all solutions of an underdeterminated system.
Are there any Haskell bindings for quadratic programming libraries?
If not, which one should I write simplified bindings for assuming I cannot avoid needing one? Is there a reasonably canonically favored open source library for this?
There probably isn't. Way back in the day I had to whip up my own linear programming bindings -- glpk-hs -- but I doubt anything's come along for quadratic programming since then.