Solving time in MATLAB - matlab

I am trying to solve an SOCP in MATLAB using CVX. After solving it, in the workspace, the time to solve it is written as cvx_cputime=48.6250, while in the command window, it is written Total CPU time (secs) = 5.04.
Can anyone please explain what is the difference between the two? I am not able to find it anywhere. And which one should I consider as the time to solve the problem?

Related

use number of solutions rather than maximum time to end solve attempts

I am using the CP-SAT solver on a JSP.
I am iterating so the solver runs many times (basically simulating each day for a year), I do not need to find the optimal solution, just a reasonably good one, so I would like to be a bit smarter on ending the solver than simply allowing it to run for X seconds each time. For example, i would like to take the 5th solution each time, or even to stop once the current solution makespan is only 5% (for example) shorter than the previous solution.
Is this possible? I am only aware of solver.parameters.max_time_in_seconds as a way of limiting the calculation time. Intermediate solutions are printed by SolutionPrinter but i think this is output only and there is no way to break the solver during a run?
wrong, you can stop the search in a callback, see this recipe:
https://github.com/google/or-tools/blob/stable/ortools/sat/docs/solver.md#stopping-search-early

OR-Tools optimization eith CP-Sat

I'm solving an optimization problem in python with OR-Tools / CP-sat solver. I'm using a file that takes some hours to reach optimal solution. Is there any way of seeing in the terminal how the process is going, like the best solution found so far, the elapsed time, etc...? I know that with cplex solver we can see this.
Thank you
First, you need to add log_search_progress:true to the parameters.
Second, a good way to speed solving it to use multiple workers. This is done by using the num_search_workers:XXX parameter. If you have a decent machine, XXX=8 is good. If you have a beefier machine, you can try XXX=12 or 16 (or more).

Matlab 2018B Detect if a variable has changed from previous sampling

I came across hasChanged(var_name) to know if var_name changed from previous. I tried to implement in my matlab 2018b. Surprisingly it did not work saying not found?
Any idea how to implement it here?

Using Gurobi to run a MIQP: how can I improve time performance?

I am using Gurobi to run a MIQP (Mixed Integer Quadratic Programming) with linear constraints in Matlab. The solver is very slow and I would like your help to understand whether I can do something about it.
These are the lines which I use to launch the problem
clear model;
clear params;
model.A=[Aineq; Aeq];
model.rhs=[bineq; beq];
model.sense=[repmat('<', size(Aineq,1),1); repmat('=', size(Aeq,1),1)];
model.Q=Q;
model.obj=c;
model.vtype=type;
model.lb=total_lb;
model.ub=total_ub;
params.MIPGap=10^(-1);
result=gurobi(model,params);
This is a screenshot of the output in the Matlab window.
Question 1: It is the first time I am trying to run a MIQP and I would like to have your advice to understand what I can do to improve performance. Let me tell what I have tried so far:
I cheated by imposing params.MIPGap=10^(-1). In this way the phase of node exploration is made shorter. What are the cons of doing this?
I have big-M coefficients and I have tied them to the smallest possible values.
I have tried setting params.ScaleFlag=2; params.ObjScale=2 but it makes things slower
I have changed params.method but it does not seem to help (unless you have some specific recommendation)
I have increase params.Threads but it does not seem to help
Question 2 (minor): Why do I get a negative objective in the root simplex log? How can the objective function be negative?
Without having the full model here, there is not much on advise to give. Tight Big-M formulations are important, but you said, you checked them already. Sometimes splitting them up might help, but this is a complex field.
What might give great benefits for some problems is using the Gurobi parameter tuning tool. So try to export your model and feed the tuning tool with it. It automatically tries different of the hundreds of tuning parameters and might give some nice results.
Regarding the question about negative objectives in the simplex logs, I can think of a couple of possible explanations. First, note that the negative objective values occur in the presence of dual infeasibilities in the dual simplex run. In such a case, I'm not sure exactly what the primal objective values correspond to. Second, if you have a MIQP with products of binaries in the objective, Gurobi may convexify the objective in a way that makes it possible for a negative objective to appear in the reformulated model even when the original model must have a nonnegative objective in any feasible solution.

Matlab runtime monotonically increases by independent runs

I am trying to solve a mixed integer linear program via YALMIP using Gurobi optimizer. I solve a problem which has a specific result I know. However, when I start Matlab in my computer for the first time it is being solved in 0.5 seconds. I clear everything and run the code again. The same result is coming in 0.8 seconds. Then, 1 seconds and so on. How can I really fix this? I am clearing the workspace after each run!