Assignment optimization / Set covering - variable-assignment

I have the following task and didn't find any working solution.
I need to find a optimal solution for network node placement. The objective is to minimize the digging cost for connecting cables. Some digging costs depending on each other. E.g. imagine you have 2 nodes in a row and dig one cable to the first then you don't have to include this digging costs to the fist node for the digging to the second node. But if you just select the second node you have to add the costs for digging to node 1 and from node 1 to node 2.
For each node there is a certain number of users which can be supplied by it. To reach a user coverage of at least e.g. 90 % of the users is the constraint.
I tried to use quadratic programming but cvx doesn't like it:
cvx_begin
variable x(n,1) binary;
minimize( x'*Q*x )
subject to
x'*A*x >= 0.9;
cvx_end
Is there anyone having a better idea... using e.g binary linear or quadratic programming?
Thanks and BR

x'Ax is a summation of a(i,j)*x(i)*x(j). The products z(i,j)=x(i)*x(j) can be linearized by:
z(i,j) <= x(i)
z(i,j) <= x(j)
z(i,j) >= x(i)+x(j)-1
z(i,j) in {0,1}
With this you have a linear MIP problem.
There are a few optimizations we can use in this formulation:
We can make A and Q triangular matrices by exploiting symmetry
The diagonals can be handled specially as x(i)^2=x(i)
The z(i,j)'s can be reduced to a strictly triangular structure

Related

How to solve that recurence by itrative method ....?

I have tried but faild to find big o of
T(n)=3t(n/3)+n/lg(n)
Can anyone please give me a solution
A good way to visualize this problem is a Recursive Tree Diagram.
The first three levels of the tree are drawn here.
For the first level, we have a total work of n / lg n
For the second level, we have 3 calls of (n/3) / lg (n/3). Summing these calls gives a total work of n / lg (n/3) at this level.
For the third level, we have 9 calls of (n/9) / lg (n/9). Summing these calls gives a total work of n / lg (n/9) or n / lg (n/3^2) at this level.
The recursive calls will continue until we have a call of T(1). This condition is met at n/3^k = 1 or k = log3(n)
So now we have a simple summation of all of the levels equal to this.
n is a constant and can be pulled out of the equation. Expanding the summation then gives this equation.
We can simplify this summation as shown here.
In Big Theta, the summation can be simplified to Θ(n*(1+log(logn)) as the summation is a harmonic series.
Simplifying further, we have Θ(n+n*log(logn)) and due to the rules of Big Theta, we can simplify to a final Big Theta of Θ(nlog(logn)) as the first n will grow at a slower rate and doesn't really matter in our final equation.
But wait! You asked for Big O. Thankfully, Big Theta provides both an upper and lower bound for the problem. Big O only provides an upper bound. What does this mean for us? Big Theta actually is Big O, but not the other way around allowing you to say that the recurrence relation is O(nlog(logn)).
Hope this helps!

Solving equations involving dozens of ceil and floor functions in MATLAB?

I am tackling a problem which uses lots of equations in the form of:
where q_i(x) is the only unknown, c_i, C_j, P_j are always positive. We have two cases, the first when c_i, C_j, P_j are integers and the case when they are real. C_j < P_j for all j
How is this type of problems efficently solved in MATLAB especially when the number of iterations N is between 20 - 100?
What I was doing is q_i(x) - c_i(x) must be equal to the summation of integers. So i was doing an exhaustive search for q_i(x) which satisfies both ends of the equation. Clearly this is computationally exhaustive.
What if c_i(x) is a floating point number, this will even make the problem even more difficult to find a real q_i(x)?
MORE INFO: These equations are from the paper "Integrating Preemption Threshold to Fixed Priority DVS Scheduling Algorithms" by Yang and Lin.
Thanks
You can use bisection method to numerically find zeros of almost any well-behavior functions.
Convert your equation problem into a zero-finding problem, by moving all things to one side of the equal sign. Then find x: f(x)=0.
Apply bisection method equation solver.
That's it! Or may be....
If you have specific range(s) where the roots should fall in, then just perform bisection method for each range. If not, you still have to give a maximum estimation (you don't want to try some number larger than that), and make this as the range.
The problem of this method is for each given range it can only find one root, because it's always picking the left (or right) half of the range. That's OK if P_j is integer, as you can always find a minimum step of the function. Say P_j = 1, then only a change in q_i larger than 1 leads to another segment (and thus a possible different root). Otherwise, within each range shorter than 1 there will be at most one solution.
If P_j is an arbitrary number (such as 1e-10), unless you have a lower limit on P_j, most likely you are out of lucky, since you can't tell how fast the function will jump, which essentially means f(x) is not a well-behavior function, making it hard to solve.
The sum is a step function. You can discretize the problem by calculating where the floor function jumps for the next value; this is periodic for every j. Then you overlay the N ''rhythms'' (each has its own speed specified by the Pj) and get all the locations where the sum jumps. Each segment can have exactly 0 or 1 intersection with qi(x). You should visualize the problem for intuitive understanding like this:
f = #(q) 2 + (floor(q/3)*0.5 + floor(q/4)*3 + floor(q/2)*.3);
xx = -10:0.01:10;
plot(xx,f(xx),xx,xx)
For each step, it can be checked analytically if an intersection exists or not.
jumps = unique([0:3:10,0:4:10,0:2:10]); % Vector with position of jumps
lBounds = jumps(1:end-1); % Vector with lower bounds of stairs
uBounds = jumps(2:end); % Vector with upper bounds of stairs
middle = (lBounds+uBounds)/2; % center of each stair
fStep = f(middle); % height of the stairs
intersection = fStep; % Solution of linear function q=fStep
% Check if intersection is within the bounds of the specific step
solutions = intersection(intersection>=lBounds & intersection<uBounds)
2.3000 6.9000

How to find this solution with matlab?

I'm beginner at matlab, and I'm interested how to find the solution of equation :
2x + y <= 6
4x + 5y <= 20
x + 2y >= 4
5x + 3y <= 15
x - 2y + 6 <= 0
how to graph this equation in matlab?
Thanks in advance
In response to some of the comments, I want to say that it does make sense to have these 5 equations in 2 unknowns. First of all, these are inequalities, not equalities. Each of them represent half side of the 2D plane after being cut by a line (all different lines). And your solution to this system of inequality is just the area that is intersection of all these half planes. It could be a closed polygon region, or an unbounded region, or empty set.
Since this looks like an assignment question, I'm not gonna given you the solution here. But here's a hint, densely sample points from XY plane, and for each point, if it satisfies all the equations, plot it, otherwise don't ...
P.S. even if there are all equalities, the system of more linear equations than variables still make sense. It's an overdetermined system, and there is solution in the "least square" sense, i.e. line fit to lots of noisy data with the lowest sum of squared error. But this is not your scenario.
This can be solved by a simplex (optimization method, linear programming) which is totally deterministic hence a computer can achieve the job. Matlab provide tools for this such as linprog. Inequations are your constraints and will define a convex polytope which can be bounded, unbounded or empty. And your goal function is equals to 1.

MATLAB: fast and memory efficient solution of a particular linear program

I have a little programming experience, so I'm pretty sure I didn't code the problem in the optimal way, so I would be happy to hear any hints.
I have two parameters: the dimension of the problem n and an N x N matrix of constraints B where N = 2n. In my case B is symmetric and has only positive values. I need to solve the following problem
That is I need to maximize a certain average of the distances subject to constraints on pairwise distances given by B(i,j).
They way I'm doing it now is an implementation of linprog(-f,A,b) where
f = ones([1,n])/n;
f = [f -f]
and
b = reshape(B',numel(B),[])
and A is defined as follows
A = zeros([N^2,N]);
for i = 1:N
for j = 1:N
if i ~= j
A((i-1)*N + j,i) = 1;
A((i-1)*N + j,j) = -1;
end
end
end
However, when n = 500 even a simple construction of A takes quite some time, not to say how long does the solution of the linear program take. Any hints are highly appreciated and please feel free to retag.
First of all, try constructing A like so:
AI = eye(N);
AV = ones(N, 1);
A = kron(AI, AV) - kron(AV, AI);
I think it should run by at least an order of magnitude faster than the way you're creating it.
In addition to creating your problem matrix in a more efficient way, you may want to look into using glpk with the glpkmex interface for MATLAB. I've found that my solution times can decrease substantially. You may see another order of magnitude decrease depending on the problem size.
If you are an academic you can get either CPLEX or Gurobi licenses for free, which should net you further decreases in solution time without a lot of fiddling around with solver parameters. This may be necessary with a problem of the size you describe.

Minimization of L1-Regularized system, converging on non-minimum location?

This is my first post to stackoverflow, so if this isn't the correct area I apologize. I am working on minimizing a L1-Regularized System.
This weekend is my first dive into optimization, I have a basic linear system Y = X*B, X is an n-by-p matrix, B is a p-by-1 vector of model coefficients and Y is a n-by-1 output vector.
I am trying to find the model coefficients, I have implemented both gradient descent and coordinate descent algorithms to minimize the L1 Regularized system. To find my step size I am using the backtracking algorithm, I terminate the algorithm by looking at the norm-2 of the gradient and terminating if it is 'close enough' to zero(for now I'm using 0.001).
The function I am trying to minimize is the following (0.5)*(norm((Y - X*B),2)^2) + lambda*norm(B,1). (Note: By norm(Y,2) I mean the norm-2 value of the vector Y) My X matrix is 150-by-5 and is not sparse.
If I set the regularization parameter lambda to zero I should converge on the least squares solution, I can verify that both my algorithms do this pretty well and fairly quickly.
If I start to increase lambda my model coefficients all tend towards zero, this is what I expect, my algorithms never terminate though because the norm-2 of the gradient is always positive number. For example, a lambda of 1000 will give me coefficients in the 10^(-19) range but the norm2 of my gradient is ~1.5, this is after several thousand iterations, While my gradient values all converge to something in the 0 to 1 range, my step size becomes extremely small (10^(-37) range). If I let the algorithm run for longer the situation does not improve, it appears to have gotten stuck somehow.
Both my gradient and coordinate descent algorithms converge on the same point and give the same norm2(gradient) number for the termination condition. They also work quite well with lambda of 0. If I use a very small lambda(say 0.001) I get convergence, a lambda of 0.1 looks like it would converge if I ran it for an hour or two, a lambda any greater and the convergence rate is so small it's useless.
I had a few questions that I think might relate to the problem?
In calculating the gradient I am using a finite difference method (f(x+h) - f(x-h))/(2h)) with an h of 10^(-5). Any thoughts on this value of h?
Another thought was that at these very tiny steps it is traveling back and forth in a direction nearly orthogonal to the minimum, making the convergence rate so slow it is useless.
My last thought was that perhaps I should be using a different termination method, perhaps looking at the rate of convergence, if the convergence rate is extremely slow then terminate. Is this a common termination method?
The 1-norm isn't differentiable. This will cause fundamental problems with a lot of things, notably the termination test you chose; the gradient will change drastically around your minimum and fail to exist on a set of measure zero.
The termination test you really want will be along the lines of "there is a very short vector in the subgradient."
It is fairly easy to find the shortest vector in the subgradient of ||Ax-b||_2^2 + lambda ||x||_1. Choose, wisely, a tolerance eps and do the following steps:
Compute v = grad(||Ax-b||_2^2).
If x[i] < -eps, then subtract lambda from v[i]. If x[i] > eps, then add lambda to v[i]. If -eps <= x[i] <= eps, then add the number in [-lambda, lambda] to v[i] that minimises v[i].
You can do your termination test here, treating v as the gradient. I'd also recommend using v for the gradient when choosing where your next iterate should be.