Using min/max *within* an Integer Linear Program - max

I'm trying to set up a linear program in which the objective function adds extra weight to the max out of the decision variables multiplied by their respective coefficients.
With this in mind, is there a way to use min or max operators within the objective function of a linear program?
Example:
Minimize
(c1 * x1) + (c2 * x2) + (c3 * x3) + (c4 * max(c1*x1, c2*x2, c3*x3))
subject to
#some arbitrary integer constraints:
x1 >= ...
x1 + 2*x2 <= ...
x3 >= ...
x1 + x3 == ...
Note that (c4 * max(c1*x1, c2*x2, c3*x3)) is the "extra weight" term that I'm concerned about. We let c4 denote the "extra weight" coefficient. Also, note that x1, x2, and x3 are integers in this particular example.
I think the above might be outside the scope of what linear programming offers. However, perhaps there's a way to hack/reformat this into a valid linear program?
If this problem is completely out of the scope of linear programming, perhaps someone can recommend an optimization paradigm that is more suitable to this type of problem? (Anything that allows me to avoid manually enumerating and checking all possible solutions would be helpful.)

Add in an auxiliary variable, say x4, with constraints:
x4 >= c1*x1
x4 >= c2*x2
x4 >= c3*x3
Objective += c4*x4

Related

Gas mixture algorithm

I have a pool of ten different gas mixtures. Each gas mixture is made of nitrogen, oxygen and carbon dioxide in different percentages.
The goal is to mix and match sets of gasses to to get a requested percentage output.
Lets say we want 33-33-33 out. Whats the best methodology to select the best subset of gases and mixing proportions to get an optimal output?
Just solve 3 equations with 3 unknowns.
if mixture 1 has a1 fraction of chemical a (and similarly with other chemicals/mixtures), and you need xa : xb : xc mixture, where xa+xb+xc=1, this will be:
a1 * x1 + a2 * x2 + a3 * x3 = xa
b1 * x1 + b2 * x2 + b3 * x3 = xb
c1 * x1 + c2 * x2 + c3 * x3 = xc
Solve for x1, x2, x3. If you get negative numbers (or no solutions), this means that it's impossible to get the wanted mixture.

resolve a system of linked equations with different modulo

Is there any algorithm to solve a system of equations expressed in different modulo spaces?
For exemple, consider this system of equations:
(x1 + x2 ) % 2 = 0
( x2 + x3) % 2 = 0
(x1 + x2 + x3) % 3 = 2
One of the solutions of this system is:
x1 = 0
x2 = 2
x3 = 0
How could I arithmetically find this solution (without using a brute force algorithm)?
Thanks
You can rewrite these equations as
x1 + x2 = 2*n1
x2 + x3 = 2*n2
x1 + x2 + x3 = 3*n3 + 2
Now, this is a linear Diophantine equation problem for which there are solutions in the literature.
Example: http://www.wikihow.com/Solve-a-Linear-Diophantine-Equation
Also see: https://www.math.uwaterloo.ca/~wgilbert/Research/GilbertPathria.pdf
Algorithm:
Write xi as a function of nks
In this case:
x3 = 3*n3 + 2 - 2*n1
x2 = 2*n2 - (3*n3 + 2 - 2*n1)
x1 = 2*n1 - (2*n2 - (3*n3 + 2 - 2*n1))
Since there is no division on the right-hand side, pick any (n1, n2, n3) and you should get a solution.
First line is same as saying x1, x2 is all even or all odd numbers.
Second line is same as saying x2, x3 is all even or all odd numbers.
Hence x1,x2,x3 is all even or all odd numbers.
From third line we can replace the question to "3 odd or 3 even numbers that accumulate to 3k+2."
You can convert your system to modulo LCM (least common multiple). Just find the LCM of all equation's modulo, and multiply each equation appropriately.

How to optimize using Genetic Algorithm to get integer values?

Say I have 3 parameters x1, x2 and x3, where x1, x2 and x3 can all take integer values between 0 to 9. I use GA to minimize an objective function f(x1,x2,x3), but the values of x1, x2 and x3 obtained should be integers. Any R-based implementation of GA with such a function to obtain integer values instead of the usual real values would be helpful.

Best way to do an iteration scheme

I hope this hasn't been asked before, if so I apologize.
EDIT: For clarity, the following notation will be used: boldface uppercase for matrices, boldface lowercase for vectors, and italics for scalars.
Suppose x0 is a vector, A and B are matrix functions, and f is a vector function.
I'm looking for the best way to do the following iteration scheme in Mathematica:
A0 = A(x0), B0=B(x0), f0 = f(x0)
x1 = Inverse(A0)(B0.x0 + f0)
A1 = A(x1), B1=B(x1), f1 = f(x1)
x2 = Inverse(A1)(B1.x1 + f1)
...
I know that a for-loop can do the trick, but I'm not quite familiar with Mathematica, and I'm concerned that this is the most efficient way to do it. This is a justified concern as I would like to define a function u(N):=xNand use it in further calculations.
I guess my questions are:
What's the most efficient way to program the scheme?
Is RecurrenceTable a way to go?
EDIT
It was a bit more complicated than I tought. I'm providing more details in order to obtain a more thorough response.
Before doing the recurrence, I'm having problems understanding how to program the functions A, B and f.
Matrices A and B are functions of the time step dt = 1/T and the space step dx = 1/M, where T and M are the number of points in the {0 < x < 1, 0 < t} region. This is also true for vector the function f.
The dependance of A, B and f on x is rather tricky:
A and B are upper and lower triangular matrices (like a tridiagonal matrix; I suppose we can call them multidiagonal), with defined constant values on their diagonals.
Given a point 0 < xs < 1, I need to determine it's representative xn in the mesh (the closest), and then substitute the nth row of A and B with the function v( x) (transposed, of course), and the nth row of f with the function w( x).
Summarizing, A = A(dt, dx, xs, x). The same is true for B and f.
Then I need do the loop mentioned above, to define u( x) = step[T].
Hope I've explained myself.
I'm not sure if it's the best method, but I'd just use plain old memoization. You can represent an individual step as
xstep[x_] := Inverse[A[x]](B[x].x + f[x])
and then
u[0] = x0
u[n_] := u[n] = xstep[u[n-1]]
If you know how many values you need in advance, and it's advantageous to precompute them all for some reason (e.g. you want to open a file, use its contents to calculate xN, and then free the memory), you could use NestList. Instead of the previous two lines, you'd do
xlist = NestList[xstep, x0, 10];
u[n_] := xlist[[n]]
This will break if n > 10, of course (obviously, change 10 to suit your actual requirements).
Of course, it may be worth looking at your specific functions to see if you can make some algebraic simplifications.
I would probably write a function that accepts A0, B0, x0, and f0, and then returns A1, B1, x1, and f1 - say
step[A0_?MatrixQ, B0_?MatrixQ, x0_?VectorQ, f0_?VectorQ] := Module[...]
I would then Nest that function. It's hard to be more precise without more precise information.
Also, if your procedure is numerical, then you certainly don't want to compute Inverse[A0], as this is not a numerically stable operation. Rather, you should write
A0.x1 == B0.x0+f0
and then use a numerically stable solver to find x1. Of course, Mathematica's LinearSolve provides such an algorithm.

Same result from K-means and sequential K-means?

Do we obtain the same result if we apply K-means and sequential K-means methods to the same dataset with the same initial settings? Explain your reasons.
Personally I think the answer is No. The result obtained by sequential K-means depends on the presentation order of the data points. And the ending condition is not the same.
Here attaches the pseudo code of the two clustering algorithms.
K-means
Make initial guesses for the means m1, m2, ..., mk
Until there is no change in any mean
Assign each data point to the cluster whose mean is the nearest.
Calculate the mean of each cluster.
For i from 1 to k
Replace mi with the mean of all examples for cluster i.
end_for
end_until
Sequential K-means
Make initial guesses for the means m1, m2, ..., mk
Set the counts n1, n2, ..., nk to zero
Until interrupted
Acquire the next example, x
If mi is closest to x
Increment ni
Replace mi by mi + (1/ni)*(x - mi)
end_if
end_until
Correct, the results may be different.
Points: x1 = (0,0), x2 = (1,1), x3 = (0.75,0), x4 = (0.25,1); m1 = (0,0.5), m2 = (1,0.5). K-means assigns x1 and x4 to the m1-cluster, x2 and x3 to the m2-cluster. The new means are m1' = (0.125,0.5) and m2' = (0.875,0.5), and no reassignment takes place. With sequential K-means, after x1 is assigned, m1 moves to (0,0), x2 moves m2 to (1,1). Then m1 is closest mean to x3, so m1 moves to (0.375,0). Finally, m2 is closest to x4, so m2 moves to (0.625,1). This is again a stable configuration.

Resources