I want to calculate relative optimality Gap of a MIP Problem also i want to abort runs at a certain run time. this method:
F(1)
abs(mymodel.objest - mymodel.objval)/max(abs(mymodel.objest),abs(mymodel.objval))
is not consistent with gap which GAMS calculate in log. GAMS uses "Best Integer" to find gap not current objective value. which one is correct?
and How can i save current "Best Integer" into a parameter ( like .objval).
and finally calculating relative optimality Gap in a benders algorithm is right this way?
rgap = (upperBound - lowerBound)/(1 + abs(upperBound));
What GAMS Calculate using "MIP Solution"
MIP Solution: 3334501534.000555 (1625 iterations, 0 nodes)
Final Solve: 56330158.829040 (2561 iterations)
Best possible: 48915652.476336
Absolute gap: 3285585881.524219
Relative gap: 0.985330
F(1) calculated gap using mymodel.objval (mymodel.objval return "Final Solve") so calculated gap is %13 and mymodel.objval value is 5.633016E+7 (GAMS calculated gap is %98). so i need to save "MIP Solution" to a parameter to export it to a excel file.
There are different formulas to calculate the relative optimality gap. It depends on the solver you use, which one is applied. Some info about this can be found in the description of the GAMS option optCR . The solver manual of the solver you use could have more details about the formula actually applied.
EDIT after question was updated:
As you wrote mymodel.objval returns the Final Solve value. If you want to see the MIP Solution value instead (as the Cplex link does it internally), you could deactivate the final solve. However, if Final Solve and MIP Solution are so much different as in your example this is often an indication for some problem (usually, they are (nearly) identical). Often, this indicates a poorly scaled model. Maybe you could improve the situation by tightening the Cplex tolerances (see Cplex options epopt, eprhs, epint) and activating aggressive scaling (Cplex option scaind 2). Activating mipkappastats (https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXmipkappastats) and quality (https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXquality) could give you more information. DataCheck=2 (https://www.gams.com/latest/docs/S_CPLEX.html#CPLEXdatacheck) might show some problems.
Related
In Julia JuMP, I am wondering whether it is possible to access an array, or similar, of the GAP history, the GAP improvements.
I know that at the end of the optimization, I can access the final gap with relative_gap(m) with m of type Model and I want the history of improvements over the solving process.
It could be for instance a vector of Float64 in percent: gaps=[20.2, 16.7, 13.8, 5.1, 0]. In such case my problem is solved to optimality as the final gap is 0.
At the end, I would like to plot the gap improvement in function of time of solving. So maybe all values of gaps could be a couple of two elements, the gap and the solving time until this new gap improvement?
Maybe this is not possible in JuMP so you could answer for Gurobi ?
Thanks!
The Gurobi callback solution has been answered by Oscar at another post - see Julia JUMP Gurobi MIP - query and store best objective and bound at runtime.
However, since Gurobi is very serious about its TimeLimit and has low times to continue computations there is also a simpler approach (this code assumes mo is your JuMP Gurobi model):
set_optimizer_attribute(mo, "TimeLimit", 2.0)
gap_history = Float64[]
max_steps = 1800
for t in 1:max_steps
optimize!(mo)
gap = MOI.get(mo, MOI.RelativeGap())
status=termination_status(mo)
push!(gap_history, gap)
gap > 0.01 || status == MOI.TIME_LIMIT || break
end
It's not possible using JuMP in general.
You could do this in Gurobi using a solver-specific callback: https://github.com/jump-dev/Gurobi.jl#callbacks
Or you could just parse the Gurobi log file that gets printed.
In general though, this information isn't all that useful as it can be quite noisy. Why do you want it?
I'm working with point clouds taken with a Kinect. My goal is the total registration for 3D mapping of places or crops. I'm using the multiway registration code.
I'm wondering if there is a way to change the number of iterations of this code? I've seen that it only does 30 iterations by default.
What kind of iterations do you mean, the iterations performed by ICP for registration or the iterations performed during global optimization?
You can change the number of iterations for global optimization by adjusting the global optimization convergence criteria.
Instead of typing
o3d.registration.global_optimization(
pose_graph, o3d.registration.GlobalOptimizationLevenbergMarquardt(),
o3d.registration.GlobalOptimizationConvergenceCriteria(), option)
write
o3d.registration.global_optimization(
pose_graph, o3d.registration.GlobalOptimizationLevenbergMarquardt(),
o3d.registration.GlobalOptimizationConvergenceCriteria(max_iteration_lm=number_of_iterations), option)
For ICP, it works in a similar way by adjusting the ICP convergence criteria:
result_icp = o3d.registration.registration_icp(source, target,
max_correspondence_distance_coarse, np.identity(4),
o3d.registration.TransformationEstimationPointToPlane(),
o3d.registration.ICPConvergenceCriteria(max_iteration=number_of_iterations))
Hope this could help!
I am trying to explore genetic algorithms (GA) for the bin packing problem, and compare it to classical Any-Fit algorithms. However the time complexity for GA is never mentioned in any of the scholarly articles. Is this because the time complexity is very high? and that the main goal of a GA is to find the best solution without considering the time? What is the time complexity of a basic GA?
Assuming that termination condition is number of iterations and it's constant then in general it would look something like that:
O(p * Cp * O(Crossover) * Mp * O(Mutation) * O(Fitness))
p - population size
Cp - crossover probability
Mp - mutation probability
As you can see it not only depends on parameters like eg. population size but also on implementation of crossover, mutation operations and fitness function implementation. In practice there would be more parameters like for example chromosome size etc.
You don't see much about time complexity in publications because researchers most of the time compare GA using convergence time.
Edit Convergence Time
Every GA has some kind of a termination condition and usually it's convergence criteria. Let's assume that we want to find the minimum of a mathematical function so our convergence criteria will be the function's value. In short we reach convergence during optimization when it's no longer worth it to continue optimization because our best individual doesn't get better significantly. Take a look at this chart:
You can see that after around 10000 iterations fitness doesn't improve much and the line is getting flat. Best case scenario reaches convergence at around 9500 iterations, after that point we don't observe any improvement or it's insignificantly small. Assuming that each line shows different GA then Best case has the best convergence time becuase it reaches convergence criteria first.
My problem is explained in the following image
http://i.stack.imgur.com/n6mZt.png
I have a finite (but rather large) amount of such pieces that need to be stacked in a way so that the REMAINING area is the smallest possible. The pieces are locked in the horizontal axis (time) and have fixed height. They can only be stacked.
The remaining area is defined by the maximum point of the stack that depends on which pieces have been selected. The best combination in the example image would be the [1 1 0]. (The trivial [0 0 0] case will not be allowed by other constraints)
My only variables are binaries (Yes or No) for each piece. The objective is a little more complicated than what I am describing, but my greatest problem right now is how to formulate the expression
Max{Stacked_Pieces} - Stacked_Pieces_Profile
in the objective function. The result of this expression is a vector of course (timeseries) but it will be further reduced to a number through other manipulations.
Essentially my problem is how to write
Max{A} - A, where A = 1xN vector
In a way compatible with a linear (or even quadratic) objective. Or am I dealing with a non-linear problem?
EDIT: The problem is like a Knapsack problem the main difference being that there is no knapsack to fill up. i.e. the size of the knapsack varies according to the selected pieces and is always equal to the top of the stacked profile
Thanks everybody!
From what I understand you can basically try to solve it as a normal knapsack problem in multiple iterations, finding the minimal.
Now, finding the height of the knapsack is a problem, which means you need multiple iterations. Because you need to solve the knapsack problem to see if a certain height will work, you need multiple iterations.
Note that you do know an upper and a lower bound for the height. I'm not sure if rotation is applicable, but you can fill in the gaps here:
Min = max(max height of smallest piece, total size / width)
Max = sum(height of all pieces).
Basically solving it means finding the smallest height [Min <= x <= Max] that fits all pieces. The easiest way to do that is by using a 'for' loop, but you can do it better:
Try min, max, half
if half fits -> max = half; iterate (goto 1)
if half doesn't fit -> min = half; iterate (goto 1)
As for solving the knapsack problem, for each iteration, I'd check if all pieces can still be fitted. Use bit-masks and AND/OR/XOR operations if you can to speed things up.
Basically you can do it like this:
Grab bit 'x'. Fill with next block
Check if this leads to a possible solution
Find next bit that can be filled
Note that you might want to use intrinsics in C++ to speed this up. Modern CPU's are quite good with this.
As for code: I've made some code that solves the bedlam cube in the past; I'm pretty sure that if you google for that, you'll find some fast solvers.
Good luck!
I am working with a convex QCQP as the following:
Min e'Ie
z'Iz=n
[some linear equalities and inequalities that contain variables w,z, and e]
w>=0, z in [0,1]^n
So the problem has only one quadratic constraint, except the objective, and some variables are nonnegative. The matrices of both quadratic forms are identity matrices, thus are positive definite.
I can move the quadratic constraint to the objective but it must have the negative sign so the problem will be nonconvex:
min e'Ie-z'Iz
The size of the problem can be up to 10000 linear constraints, with 100 nonnegative variables and almost the same number of other variables.
The problem can be rewritten as an MIQP as well, as z_i can be binary, and z'Iz=n can be removed.
So far, I have been working with CPLEX via AIMMS for MIQP and it is very slow for this problem. Using the QCQP version of the problem with CPLEX, MINOS, SNOPT and CONOPT is hopeless as they either cannot find a solution, or the solution is not even close to an approximation that I know a priori.
Now I have three questions:
Do you know any method/technique to get rid of the quadratic constraint as this form without going to MIQP?
Is there any "good" solver for this QCQP? by good, I mean a solver that efficiently finds the global optimum in a resonable time.
Do you think using SDP relaxation can be a solution to this problem? I have never solved an SDP problem in reallity, so I do not know how efficient SDP version can be. Any advice?
Thanks.