How to output the final tableau of simplex method in docplex? - linear-programming

Is there a way to output the final tableau in python with docplex library? If not, is there a work around?
I want to use dual simplex method to solve linear programming problem with newly added constraints. So, I would need to access the final tableau to decide which variable to exit the basis, without having to re-solve the problem from scratch.

This sort of low level interaction cannot be done at the docplex level. In order to do this you can use Model.get_cplex() to get a reference to the underlying engine object. With this you can then get additional information. You can find the reference documentation for this class here. You probably want to look at the solution, solution.basis, solution.advanced properties. This should give you all the information you need.
Note that the engine works with an index oriented model in which every variable or constraint is just a number. You can convert docplex variable objects by using Model.get_var_by_index().
I also wonder whether you may want drop docplex and instead directly use the CPLEX Python API. You can find documentation of this here.

Related

How to build a "Bill Of Materials" automatically

I'm looking to auto-generate a Bill Of Materials (BOM) in draw.io by using object ID's. This is because my plans contain many of the same or similar components making it difficult to visually count. So, ultimately I'd like to auto-generate a parts list. Firstly is this possible in draw.io? Secondly what would be the best method of execution?
Currently I'm converting my diagram to PDF and then using the find function to count the number of instances of the part number.
A point in the right direction would be most welcome.

How do crypto-like software display large bytes as a graphic?

E.g: On apps like Metamask or Myetherwallet, it often displays the user's public address in a graphic, like some randomised drawing. What is this called and how does one do this?
You're probably talking about blockies. They're a specific variant of the more general idea of "identicons," which use a seed of some sort to generate an icon.
In the case of ssh-keygen (the software used by those wallets to generate keys is probably similar, but as pointed out by the other answer, may serve a different purpose), this is called the randomart and is used as an easy way for humans to validate keys.
I assume you mean the QR Code
This isn't native to Crypto or any one language in particular, it's a matrix-based bar code that can be used to store any type of information - typically URLs or text based information. Functionally, it's not much different than the barcode on your box of Frosted Flakes.
There's multiple sites that generate QR Codes for you, or you can write relatively simple software to make them for you. There's also a few QR Code API's out there that will generate them on the fly.
MetaMask is pretty clever in that actually uses a table with white/black cells instead of an image.
Looking at my MetaMask, I wonder if you actually meant the Identicon which is just a way to interpret a hash as an image.

Generate sequence of realized Cash flows from an IRS under a given scenario using QuantLib

I am new to quantlib, but I have relatively good understanding of C++. To put my question in some sort of context, I can inform you that I am actually trying to implement the portfolio CVA calculation method proposed by Giovanni Cesari (see link below) for a simple portfolio consisting of one interest rate swap (as a starting point).
I working with the Cheyette (quasi-Gaussian) interest rate model. The model has been implemented as a "new" stochastic process class and the simulated paths stored/generated as a multipath class.
However, as Cesari's method is based on LS-Monte Carlo, I need to write a code that can generate the resulting cash flow sequence from an interest rate swap under each scenario. I do not know if there is some efficient way to do this in quantlib, but I have a feeling that there is. I guess one should be able let the scenarios generated, populate Quantlib quotes which are linked to an instance of the quantlib term structures class. Hopefully I can use this together with the swap class in order to obtain the realized cash flows (basically the floating leg, as the fixed leg is deterministic) from the swap.
Any idea of how this can be done will be highly appreciated!
Link to Cesari's presentation (see page 21 to 26): http://sfi.epfl.ch/files/content/sites/sfi/files/shared/Swissquote%20Conference%202010/Cesari_talk.pdf

Best approach for doing full-text search with list-of-integers documents

I'm working on a C++/Qt image retrieval system based on similarity that works as follows (I'll try to avoid irrelevant or off-topic details):
I take a collection of images and build an index from them using OpenCV functions. After that, for each image, I get a list of integer values representing important "classes" that each image belongs to. The more integers two images have in common, the more similar they are believed to be.
So, when I want to query the system, I just have to compute the list of integers representing the query image, perform a full-text search (or similar) and retrieve the X most similar images.
My question is, what's the best approach to permorm such a search?
I've heard about Lucene, Lemur and other indexing methods, but I don't know if this kind of full-text searchs are the best way, given the domain is reduced (only integers instead of words).
I'd like to know about the alternatives in terms of efficiency, accuracy or C++ friendliness.
Thanks!
It sounds to me like you have a vectorspace model, so Lucene or a similar product may work well for you. In general, an inverted-index model will be good if:
You don't know the number of classes in advance
There are a lot of classes relative to the number of images
If your problem doesn't fit these criteria, a normal relational DB might work better, as Thomas suggested. If it meets #1 but not #2, you could investigate one of the "column oriented" non-relational databases. I'm not familiar enough with these to tell you how well they would work, but my intuition is that you'll need to replicate a lot of the functionality in an IR toolkit yourself.
Lucene is written in Java and I don't know of any C++ ports. Solr exposes Lucene as a web service, so it's easy enough to access it that way from whatever language you choose.
I don't know much about Lemur, but it looks like it has a similar vectorspace model, and it's written in C++, so that might be easier for you to use.
You can take a look at Lucene for image retrieval (LIRE) here: http://www.semanticmetadata.net/2006/05/19/lire-lucene-image-retrieval-04-released/
If I'm mistaken, you are trying to implement a typical bag of words image retrieval am I correct? If so you are probably trying to build an inverted file index. Lucene on its own is not suitable as you probably have already realized as it index text instead of numbers. Using its classes for querying the index would also be a problem as it is not designed to "parse" (i.e. detect keypoints, extract descriptors then vector-quantize them) image into the query vector.
LIRE on the other hand have been modified to index feature vectors. However, it does not appear to work out of the box for bag of words model. Also, I think I've read on the author's website that it currently uses brute force matching rather than the inverted file index to retrieve the images but I would expect it to be easier to extend than Lucene itself for your purposes.
Hope this helps.

Cross Validation in libsvm

I'm using libsvm library in my project and have recently discovered that it provides out-of-the-box cross validation.
I'm checking the documentation and it says clearly that I have to call svm-train with -n switch to use CV feature
.
When I call it with -v switch I cannot get a model file which is needed by svm-predict.
Implementing Support Vector Machine from scratch is beyond the scope of my project, so I'd rather fix this one if it is broken or ask the community for support.
Can anybody help with that?
Here's the link to the library, implemented in C and C++, and here is the paper that describes how to use it.
Cause libsvm use cv only for parameter selection.
From libsvm FAQ:
Q: After doing cross validation, why there is no model file outputted ?
Cross validation is used for selecting good parameters. After finding them, you want to re-train the whole data without the -v option.
If you are going to use cv for estimating quality of classifier on your data you should implement external cross validation by splitting data, train on some part and test on other.
It's been a while since I used libsvm so I don't think I have the answer you're looking, but if you run the cross-validation and are satisfied with the results, running lib-svm with the same parameters without the -v will yield the same model.