Get all extreme points of Linear Program in CPLEX - java

I need to enumerate all basis corresponding to all extreme points of a LP with the CPLEX API in Java. Unfortunately I did not find any way to do this with CPLEX. Is there a solution ?
If not, I will do this myself but I will need to play with basis. Is any simple way with CPLEX to enumerate all basis and check if a basis is a feasible solution ?

The short answer: no.
There is no easy way to do this. One possible approach, but somewhat cumbersome, is to encode the basis using binary variables. E.g.:
xb[i] = 1 for basic variables
0 for non-basic variables
We need to add constraints on non-basic variables: they will be at bound. I.e. for a non-negative variable x[i] we have
xb[i]=0 => x[i]=0
(this is an indicator constraint). Furthermore we know that
sum(i,xb[i]) = m
(the number of basic variables is equal to the number of rows in the model).
Then use Cplex's solution pool to enumerate all possible feasible bases. An illustration for this approach is shown in this link. (This particular example enumerates all optimal bases, but it is not difficult to tell Cplex to enumerate all feasible bases).

Related

Calculating the principal axis/eigenvalues and -vectors of large dataset in Java

I have a large dataset (>500.000 elements) that contains the stress values (σ_xx, σ_yy, σ_zz, τ_xy, τ_yz, τ_xz) of FEM-Elements. These stress values are given in the global xyz-coordinate space of the model. I want to calculate the main axis stress values and directions from those. If you're not that familiar with the physics behind it, this means taking the symmetric matrix
| σ_xx τ_xy τ_xz |
| τ_xy σ_yy τ_yz |
| τ_xz τ_yz σ_zz |
and calculating its eigenvalues and eigenvectors. Calculating each set of eigenvalues and -vectors on its own is too slow. I'm looking for a library, an algorithm or something in Java that would allow me to do this as array calculations. As an example, in python/numpy I could just take all my 3x3-matrices, stack them along a third dimension to get a nx3x3-array, and pass that to np.linalg.eig(arr), and it automatically gives me an nx3-array for the three eigenvalues and an nx3x3-array for the three eigenvectors.
Things I tried:
nd4j has an Eigen-module for calculating eigenvalues and -vectors, but only supports a single square array at a time.
Calculate the characteristic polynomial and use cardanos formula to get the roots/eigenvalues - possible to do for the whole array at once, but I'm stuck now on how to get the corresponding eigenvectors. Is there maybe a general simple algorithm to get from those to the eigenvectors?
Looking for an analytical form of the eigenvalues and -vectors that can be calculated directly: It does exist, but just no.
You'll need to write a little code.
I'd create or use a Matrix class as a dependency and find methods to give you eigenvalues and eigenvectors. The ones you found in nd4j sound like great candidates. You might also consider the Linear Algebra For Java (LA4J) dependency.
Load the dataset into a List<Matrix>.
Use functional Java methods to apply a map to give you a List of eigenvalues as a vector per stress matrix and a List of eigenvectors as a matrix per stress matrix.
You can optimize this calculation to the greatest extent possible by applying the map function to a stream. Java will parallelize the calculation under the covers to leverage available cores to the greatest extent possible.
Follow-up: This is the way that worked best for me, as I can do all operations without iterating over every element. As stated above, I'm using Nd4j, which seems to be limited in its possibilities compared to numpy (or maybe I just didn't read the documentation thoroughly enough). The following method uses only basic array operations:
From the given stress values, calculate the eigenvalues using Cardano's formula. Only element wise instructions are needed to do that (add, sub, mul, div, pow). The result should be three vectors of size n, each containing one eigenvalue for all elements.
Use the formula given here to calculate the matrix S for each eigenvalue. Like step 1, this can obviously also be done using only element-wise operations with the stress value- and eigenvalue-vectors, in order to avoid specifiying some complicated instructions on which array to multiply according to which axis while keeping whatever other axis.
Take one column from S and normalize it to get a normalized eigenvector for the given eigenvalue.
Note that this method only works if you have a real symmetric matrix. You also should make sure to properly deal with cases where the same eigenvalue appears multiple times.

special case of constraint satisfaction efficient solution

I'm trying to solve a special case of the general constraint satisfaction problem in java.
Basically I have multiple variables, each one taking discrete values, and every variable is defined by the set of all possible values it has (think of it like an enumeration in Java, that would help).
I also have multiple groupements of conditions (think of a condition as a system of multiple equations on the variables, and they are all unary constraints: in other words of the form variable = possible value), the goal is to find if there's a set of variable values that satisfies at least one condition from each group (it might satisfy multiple ones from the same group). I will call this particular set a solution. What I'm looking for is all possible solutions.
The only Idea I have so far is basically brute force.
This is a concrete example so things are clearer:
s = {a,b,c}, v = {1,2,3}, n = {p,k,m}.
First condition group:
c1 = {s=a and v=2}, c2 = {s=b}.
Second condition group:
c1={n=p and v=2}.
Third condition group:
c1={s=a and n=p}, c2 = {s=c}.
In this situation, if we take (s=a,v=2,n=p): it satisfies the first condition of all three groups, and is, therefore, a solution to the problem.
(s=b,v=2,n=p) however is not a solution, because it doesn't verify any of the third group's conditions. In fact, the number of possible solutions here is 1.
Please note that the conditions within a group are not necessarily mutually exclusive.
Any insight into a possible way to go more efficiently than by brute force be it a data structure or an algorithm would be great since I will have to solve millions of such systems of quite the number of variables (thirty variables tops of around 15 values each, and a hundred such conditions tops).
Edit1: Data Constraints
If N is the number of variables each problem will have then N<=30.
If |V| is the maximum number of elements a variable V can have, then I know that Max(|Vi|)<=15 for every variable Vi in a problem.
I also know that if C is the number of constraints per problem, then C<100.
Lastly, I know that statistically speaking, the number of solutions for the problem will be small, meaning that most problems will have one single solution, and the likelihood of having more than 8 solutions is less than 99% of the time. For the sake of optimization, we can even assume that I'm never interested in any problem that has more than 10 solutions ever.

Dynamic Programming (how to send a message in the most efficient way)

I'm having a hard time with dynamic programming, I'm new in this, so I hope you could help me with anything you can, the problem is this:
As the Communications Officer of the IKS B'Moth Klingon battle cruiser, your duty is to manage communications in the most efficient way. Assume you need to transmit a message S= s1...sm given as a string of m symbols. For this purpose, you have r different codes. Let b(ij) be the number of bits needed to enconde the i-th symbol of your message in the j-th code. Initially, the bridge transmitter is set to code #1, but you can freely change the code at any point within the message and as many times as you want. To do so, you need to send a control code which is composed of C(ij) bits if you want to switch from current code i to any other code j. Your goal is to determine how to send thee message in the most efficient way (using the least number of bits).
A) Prove the problem exhibits optimal substructure.
B) find a recurrence for the optimal number of bits required.
C) Build a bottom up dynamic programming algorithm to solve the problem and indicate its complexity.
You can make a 3 dimensional array, and use previousCode, newCode, and ithSymbol as indices. The array will store the least number of bits while scanned upto ithSymbol and when it switches code from previousCode to newCode.
The recursive formula will be:
dp(ithSymbol, previousCode, newCode)=min_(i=1 to r)(dp(ithSymbol-1,i,previousCode))+C(previousCode, newCode)+b(ithSymbol,newCode);
(Assumed, C(i,i)=0 for all i)
Now you can write the code for yourself.
N.B. This is a naive approach. You can further make it efficient by making the array 2-D as only ithSymbol-1 is used in any step.

how to use similarity algorithm for keys of hadoop map resuce job

I need to implement the following problem:
I'm getting the data of type
public class Data{
private String key;
private String valueData;
}
I need to write a map reduce job to get all unique keys, with one (random) valueData for each of them.
Sound very simple for hadoop, and Yep, I know how to implement this.
But the real problem is that, I need also to reduce all "similar" keys.
And the output should be one of the similar key with one of the dataValue
What is the best way (and how) to implemet this in hadoop? I would also like to have a flexebility to change the similarity algorithm.
Have a look at the MinHashing technique, it is widely used with MapReduce for this task.
The similarity metric is bound to Jaccard, not sure if there are other approaches. However once you computed near keys you can use another metric to measure the similarity between them, because minhashing has drastically reduced your searchspace.
You can read more on wikipedia: http://en.wikipedia.org/wiki/MinHash
Mahout has a MinHash clustering algorithm, you can have a look there. It is pretty easy to understand and features several hashing algorithms.
You essentially need to come up with a function, f, such that, as nearly as possible:
f(A) = f(B) if and only if A and B are "similar"
Now exactly how strictly you are able to conform to this is entirely dependent on what exactly the domain of these values is, and what your similarity metric is, but this is the goal.
As an example, if the keys were real numbers, then I might choose f(x) = round(x). For values of x that are very close, it is likely that f(x) will be the same, but possible that it's different, e.g., 2.45 and 2.55. But maybe you can allow this "good enough"-ness.
Then, you can just make the key to your reduce step the output of this function.
I'll also add that there are lots of other sophisticated techniques for specific similarity metrics and specific clustering methods - maybe I could point you to one of those if you gave a little more detail on what types of metrics you're hoping to use, or what exactly the "similar" keys are.

Algorithm to reduce satisfiability java

Is there any algorithm to reduce sat problem.
Satisfiability is the problem of determining if the variables of a given Boolean formula can be assigned in such a way as to make the formula evaluate to TRUE. Equally important is to determine whether no such assignments exist, which would imply that the function expressed by the formula is identically FALSE for all possible variable assignments. In this latter case, we would say that the function is unsatisfiable; otherwise it is satisfiable. To emphasize the binary nature of this problem, it is frequently referred to as Boolean or propositional satisfiability. The shorthand "SAT" is also commonly used to denote it, with the implicit understanding that the function and its variables are all binary-valued.
I have used genetic algorithms to solve this, but it would be easier if is reduced first?.
Take a look at Reduced Order Binary Decision Diagrams (ROBDD). It provides a way of compressing boolean expressions to a reduced canonical form. There's plenty of software around for performing the BDD reduction, the wikipedia link above for ROBDD contains a nice list of external links to other relevant packages at the bottom of the article.
You could probably do a depth-first path-tree search on the formula to identify "paths" - Ie, for (ICanEat && (IHaveSandwich || IHaveBanana)), if "ICanEat" is false, the values in brackets don't matter and can be ignored. So, right there you can discard some edges and nodes.
And, if while you're generating this depth-first search, the current Node resolves to True, you've found your solution.
What do you mean by "reduced", exactly? I'm going to assume you mean some sort of preprocessing beforehand, to maybe eliminate or simplify some variables or clauses first.
It all depends on how much work you want to do. Certainly you should do unit propagation until it completes. There are other, more expensive things you can do. See the pre-processing section of the march_dl page for some examples.

Categories

Resources