Infeasible or Unbounded

816 views
Skip to first unread message

Matts Davids

unread,
Oct 25, 2021, 12:02:22 AM10/25/21
to am...@googlegroups.com
Hello Sir,

I am trying to solve an optimization problem using Gurobi but the results are telling me the following:

ampl: include 2.FECS_HSC_22_10_2021.run;
Gurobi 9.0.2: nonconvex=2
Gurobi 9.0.2: infeasible or unbounded; constraint.dunbdd returned.
No basis.
Gurobi 9.0.2: nonconvex=2
Gurobi 9.0.2: infeasible or unbounded; constraint.dunbdd returned.
No basis.
Gurobi 9.0.2: nonconvex=2
Gurobi 9.0.2: infeasible or unbounded; constraint.dunbdd returned.
No basis.
Gurobi 9.0.2: nonconvex=2
Gurobi 9.0.2: infeasible or unbounded; constraint.dunbdd returned.
No basis.

Could you help me to understand how I can fix it?

Sincerely Yours,

Davids

AMPL Google Group

unread,
Oct 25, 2021, 11:16:34 AM10/25/21
to AMPL Modeling Language
When these messages appear, Gurobi has determined that the dual of your problem is infeasible: there is no way to assign values to the variables of the dual problem that will satisfy all constraints of the dual problem. Dual infeasibility implies that the original (primal) problem is either also infeasible, or is unbounded -- but Gurobi can't immediately tell which. (See "Infeasible or Unbounded" for a more detailed explanation.)

To get more specific help, replace your "option gurobi_options" command with these two commands:

option show_stats 1;
option gurobi_options 'outlev=1 nonconvex=2';


Then solve, and you will get a lot more output. Copy all of it from your terminal or console window, and paste it into a reply to this forum.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ampl/CAGnfZd7Nwt5NFWLmWcxnC%3DSD6wY6_Set1xrtRG-3ozosEe10eA%40mail.gmail.com.

Matts Davids

unread,
Oct 26, 2021, 12:44:49 PM10/26/21
to am...@googlegroups.com
Hello Sir,

Thank you for responding. I have tried to look at my codes again but I still can't understand the results that I am obtaining. In fact, my intention is to find the value of c,r, C_HC, and r_HV that give the highest profit. For the second time, I run the problem using the obtained value of c,r, C_HC, and r_HV as parameters to solve the optimization problem in the objective function to obtain the optimal profit and all the variables. Please help me to fix the issue. If possible please can you help me also to find a way to run the problem at once and get the results in MS Excel?


Attached are the files of my program.  

Sincerely,
Davids


Foodmarket.dat
Foodmarket.mod
Foodmarket.run

AMPL Google Group

unread,
Oct 27, 2021, 3:41:17 PM10/27/21
to AMPL Modeling Language
All of your optimization problems are being rejected by Gurobi as "infeasible or unbounded". However when I delete the objective function, then Gurobi does find a feasible solution. Thus it appears that your problems are unbounded: for any number M, no matter how large, there are feasible values of the variables that make your objective function larger than M. In general, unboundedness indicates that there is some kind of error in your model, which you will have to fix. There is no simple and easy way to determine the cause of unboundedness, but here are some tests that are often helpful.

First, for each variable in your objective function, check that it appears in the constraints somewhere. And for each term that is being summed to form your objective function, check that the constraints do not allow it to become infinitely large.

If the above checks do not reveal the problem, then proceed as follows. Choose M large enough that it's a value that you would not expect a variable to have in a proper optimal solution. For each variable that is not defined with a lower bound in your model, add a lower bound of -M, and for each variable that is not defined with an upper bound in your model, add an upper bound of M -- where M is some large number. (For example, "var P_b_tom {TT} >= -100000 <= 100000;".) With these bounds, Gurobi will find a finite solution. In the solution, look for variables that equal -M or M; they are the ones that were not being properly bounded by your model.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Tue, Oct 26, 2021 at 4:44 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Sir,

Thank you for responding. I have tried to look at my codes again but I still can't understand the results that I am obtaining. In fact, my intention is to find the value of c,r, C_HC, and r_HV that give the highest profit. For the second time, I run the problem using the obtained value of c,r, C_HC, and r_HV as parameters to solve the optimization problem in the objective function to obtain the optimal profit and all the variables. Please help me to fix the issue. If possible please can you help me also to find a way to run the problem at once and get the results in MS Excel?

Attached are the files of my program.

Sincerely,
Davids
On Mon, Oct 25, 2021 at 3:01 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
When these messages appear, Gurobi has determined that the dual of your problem is infeasible: there is no way to assign values to the variables of the dual problem that will satisfy all constraints of the dual problem. Dual infeasibility implies that the original (primal) problem is either also infeasible, or is unbounded -- but Gurobi can't immediately tell which. (See "Infeasible or Unbounded" for a more detailed explanation.)

To get more specific help, replace your "option gurobi_options" command with these two commands:

option show_stats 1;
option gurobi_options 'outlev=1 nonconvex=2';


Then solve, and you will get a lot more output. Copy all of it from your terminal or console window, and paste it into a reply to this forum.


--
Robert Fourer
am...@googlegroups.com

Matts Davids

unread,
Oct 28, 2021, 2:01:46 PM10/28/21
to am...@googlegroups.com
Thank you so much for the direction.

I have identified the variable that was not in the objective function but still when I run the problem I obtain a solution that I don't understand well. Can you help me again? Attached is my new codes

Foodmarket2.dat
Foodmarket2.run
Foodmarket2.mod

AMPL Google Group

unread,
Nov 1, 2021, 9:54:16 AM11/1/21
to AMPL Modeling Language
When I run "Foodmarket2.run", Gurobi gives the same "infeasible or unbounded" message as before:

ampl: include Foodmarket2.run

Presolve eliminates 2737 constraints and 2231 variables.
Adjusted problem:
738 variables:
	219 nonlinear variables
	519 linear variables
980 constraints; 2642 nonzeros
	139 nonlinear constraints
	841 linear constraints
	498 equality constraints
	482 inequality constraints
1 nonlinear objective; 245 nonzeros.

Gurobi 9.1.2: outlev=1
nonconvex=2
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (win64)
Thread count: 2 physical cores, 4 logical processors, using up to 4 threads
Optimize a model with 841 rows, 738 columns and 1947 nonzeros
Model fingerprint: 0x788ee70a
Model has 72 quadratic objective terms
Model has 139 quadratic constraints
Coefficient statistics:
  Matrix range     [3e-01, 1e+02]
  QMatrix range    [1e+00, 7e+06]
  QLMatrix range   [1e-03, 2e+05]
  Objective range  [1e+00, 3e+06]
  QObjective range [1e+00, 2e+01]
  Bounds range     [6e+00, 3e+03]
  RHS range        [1e-07, 2e+02]
  QRHS range       [1e-08, 5e+07]
Presolve removed 144 rows and 19 columns
Presolve time: 0.01s

Barrier solved model in 0 iterations and 0.01 seconds
Model is infeasible or unbounded
Gurobi 9.1.2: infeasible or unbounded

Also when I use the command "drop obj;" to drop the objective function from the problem, Gurobi finds a feasible solution. Thus it appears that your revised problem is still unbounded, and you will need to return to the instructions I gave previously for learning the cause of the infeasibility.

I notice that you say, "I have identified the variable that was not in the objective function." But to investigate infeasibility, you should look for a variable that is in the objective function but that is not in the constraints. If all of the variables in the objective function are also in the constraints, then you should try my second suggestion ("Choose M large enough . . .").


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Thu, Oct 28, 2021 at 6:01 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you so much for the direction.

I have identified the variable that was not in the objective function but still when I run the problem I obtain a solution that I don't understand well. Can you help me again? Attached is my new codes

On Wed, Oct 27, 2021 at 7:13 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
All of your optimization problems are being rejected by Gurobi as "infeasible or unbounded". However when I delete the objective function, then Gurobi does find a feasible solution. Thus it appears that your problems are unbounded: for any number M, no matter how large, there are feasible values of the variables that make your objective function larger than M. In general, unboundedness indicates that there is some kind of error in your model, which you will have to fix. There is no simple and easy way to determine the cause of unboundedness, but here are some tests that are often helpful.

First, for each variable in your objective function, check that it appears in the constraints somewhere. And for each term that is being summed to form your objective function, check that the constraints do not allow it to become infinitely large.

If the above checks do not reveal the problem, then proceed as follows. Choose M large enough that it's a value that you would not expect a variable to have in a proper optimal solution. For each variable that is not defined with a lower bound in your model, add a lower bound of -M, and for each variable that is not defined with an upper bound in your model, add an upper bound of M -- where M is some large number. (For example, "var P_b_tom {TT} >= -100000 <= 100000;".) With these bounds, Gurobi will find a finite solution. In the solution, look for variables that equal -M or M; they are the ones that were not being properly bounded by your model.


--
Robert Fourer
am...@googlegroups.com

Matts Davids

unread,
Nov 3, 2021, 11:52:28 AM11/3/21
to am...@googlegroups.com
Hello Sir,

I have tried to revise my problem again by if all of the variables in the objective function are also in the constraints and I fixed some flows. The program is running very slowly without terminating. Can you help me to check once again? 

Sincerely Yours,
Davids

Foodmarket3.mod
Foodmarket3.dat
Foodmarket3.run

AMPL Google Group

unread,
Nov 4, 2021, 1:53:08 PM11/4/21
to AMPL Modeling Language
Your revised program seems to be running correctly. At least, Gurobi is finding optimal solutions to many problems; the output from "include Foodmarket3.run" starts like this,

ampl: include Foodmarket3.run
Gurobi 9.1.2: nonconvex=2
Gurobi 9.1.2: optimal solution; objective -10330657.64
31013 simplex iterations
No basis.
No dual variables returned.
Gurobi 9.1.2: nonconvex=2
Gurobi 9.1.2: optimal solution; objective -10923740.76
46105 simplex iterations
No basis.
No dual variables returned.
Gurobi 9.1.2: nonconvex=2
Gurobi 9.1.2: optimal solution; objective -11266288.97
20471 simplex iterations
No basis.
No dual variables returned.
Gurobi 9.1.2: nonconvex=2
Gurobi 9.1.2: optimal solution; objective -11497948.79
28768 simplex iterations
No basis.
No dual variables returned.
Gurobi 9.1.2: nonconvex=2
Gurobi 9.1.2: optimal solution; objective -11670676.71
25599 simplex iterations
No basis.
No dual variables returned.

and continues for many more solves. However, you are solving in a loop,

for {cval in 2..C_Max, rval in 1..R_Max, N_HC_val in 2..N_HC_Max, r_HV_val in 1..R_HV_Max} { ...

and the set following "for" has 7200 members, so you are going to have to wait a long time for all 7200 solves to be completed.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Wed, Nov 3, 2021 at 3:52 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Sir,

I have tried to revise my problem again by if all of the variables in the objective function are also in the constraints and I fixed some flows. The program is running very slowly without terminating. Can you help me to check once again?

Sincerely Yours,
Davids

Matts Davids

unread,
Nov 4, 2021, 8:13:33 PM11/4/21
to am...@googlegroups.com
Is there any possibility that you can recommend obtaining the value of c, r, N_HC, and r_HV that gives the optimal solution without solving in a loop? I need your help, please!

Davids,

AMPL Google Group

unread,
Nov 8, 2021, 3:37:37 PM11/8/21
to AMPL Modeling Language
It would be possible to make one or more of your four loop parameters -- c, r, N_HC, and r_HV -- into a variable of the problem, so that you would have a lot fewer problems to solve. However, because of the way that those parameters are used in the model, I expect that making even one of them into a variable would cause the resulting problems to be much harder to solve. Thus, I do not expect that this approach would be helpful.

I notice that you are asking Gurobi to solve every one of the 7200 problems to within the optimality tolerance. (By default, Gurobi stops when the gap between its lower and upper bounds on the objective differ by 0.01% or less.) Do you need to know the optimal value of your model for every one of the 7200 different choices of the parameters, or is it enough to know the optimal value for the choice that is best? If you say that you only need to know the optimal value for the choice that is the best, then I can suggest a way to greatly reduce the Gurobi solving time.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Fri, Nov 5, 2021 at 12:13 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Is there any possibility that you can recommend obtaining the value of c, r, N_HC, and r_HV that gives the optimal solution without solving in a loop? I need your help, please!

Davids,

Matts Davids

unread,
Nov 8, 2021, 8:42:30 PM11/8/21
to am...@googlegroups.com
In the model, I would like to consider -- c, r, N_HC, and r_HV-- s variables of the problem and solve to know the optimal value of my model (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Please suggest to me the way to greatly reduce the Gurobi solving time.

I also have Minos solver and cplex if any combination can work better than gurobi, I can consider it. 

Matts Davids

unread,
Nov 12, 2021, 9:23:37 AM11/12/21
to am...@googlegroups.com
Hello Sir,

I would like to know the optimal value (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Is there any possibility of solving with integer variables the value of c, r, N_HC, and r_HV without using the for loop? Can you please suggest to me the way to greatly reduce the Gurobi solving time? I need your help please.

Sincerely,
Leon

AMPL Google Group

unread,
Nov 15, 2021, 10:23:38 AM11/15/21
to AMPL Modeling Language
Also as I mentioned previously, it would be possible to make one or more of your four loop parameters -- c, r, N_HC, and r_HV -- into a variable of the problem, so that you would have fewer problems to solve. However, because of the way that those parameters are used in the model, making them into variables would cause the resulting problems to be much harder to solve. Thus, the overall solution time might not be reduced.

For example, you could consider making N_HC into a variable:

   var N_HC integer >= 1, <= N_HC_Max;

But then there are two parameters (Start_hv and theta_hv) that depend on N_HC, and that will also have to be changed into variables. Also N_HC appears in the objective function. But the real trouble is that N_HC appears in many constraints in contexts where a variable is not permitted. For example,

  subject to pzero_HV{t in TT}:
     P_0_hv[t] = (sum{i in 0..(N_HC-1)}((((N_HC*Start_hv[t])^i)/(fact[i]))) +
     (((N_HC*Start_hv[t])^N_HC)/(fact[N_HC]))*
     ((1 - (Start_hv[t]*(m_hv[t]^(r_HV))))/(1-Start_hv[t])) )^-1;

You cannot write "sum{i in 0..(N_HC-1)}" where N_HC is a variable, or fact[N_HC] where fact is a param and N_HC is a variable; also Gurobi will not accept a highly nonlinear expression like ((N_HC*Start_hv[t])^N_HC) where N_HC is a variable. So you can see that your model would require significant reformulations to permit N_HC to be a variable, and then it could happen that the reformulated model is much more difficult to solve.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Mon, Nov 15, 2021 at 3:11 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
The Gurobi log shows the following message (when outlev=1 is set):

Continuous model is non-convex -- solving as a MIP.

So I had the idea to use the Gurobi option bestbndstop=r, which only works with MIP (branch-and-bound) solves. This option stops the optimization as soon as the upper bound (for a maximization) is <= r. So if you set r to the best optimal objective value seen so far, then when the loop tries other values of c, r, N_HC, r_HV, the optimization will be stopped as soon as the MIP algorithm proves that the objective cannot be improved using those values.

However, when I implement this idea using Gurobi, I get error messages indicating that there may be a bug. I am reporting this problem now, and hopefully it will be fixed soon; I will post an update here when there is a fix available. Until then, your best bet may be to just wait for all 7200 problems to solve.

Currently Gurobi is the only solver that uses a MIP approach to solve non-convex continuous quadratic problems to global optimality, and that has an option like bestbndstop.

See also my follow-up in the next message.


--
Robert Fourer
am...@googlegroups.com
On Fri, Nov 12, 2021 at 2:23 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Sir,

I would like to know the optimal value (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Is there any possibility of solving with integer variables the value of c, r, N_HC, and r_HV without using the for loop? Can you please suggest to me the way to greatly reduce the Gurobi solving time? I need your help please.

Sincerely,
Leon

On Tue, Nov 9, 2021 at 1:42 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
In the model, I would like to consider -- c, r, N_HC, and r_HV -- as variables of the problem and solve to know the optimal value of my model (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Please suggest to me the way to greatly reduce the Gurobi solving time.


I also have Minos solver and cplex if any combination can work better than gurobi, I can consider it.
On Mon, Nov 8, 2021 at 8:37 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It would be possible to make one or more of your four loop parameters -- c, r, N_HC, and r_HV -- into a variable of the problem, so that you would have a lot fewer problems to solve. However, because of the way that those parameters are used in the model, I expect that making even one of them into a variable would cause the resulting problems to be much harder to solve. Thus, I do not expect that this approach would be helpful.

I notice that you are asking Gurobi to solve every one of the 7200 problems to within the optimality tolerance. (By default, Gurobi stops when the gap between its lower and upper bounds on the objective differ by 0.01% or less.) Do you need to know the optimal value of your model for every one of the 7200 different choices of the parameters, or is it enough to know the optimal value for the choice that is best? If you say that you only need to know the optimal value for the choice that is the best, then I can suggest a way to greatly reduce the Gurobi solving time.


--
Robert Fourer
am...@googlegroups.com

AMPL Google Group

unread,
Nov 15, 2021, 10:57:35 AM11/15/21
to AMPL Modeling Language
The Gurobi log shows the following message (when outlev=1 is set):

Continuous model is non-convex -- solving as a MIP.

So I had the idea to use the Gurobi option bestbndstop=r, which only works with MIP (branch-and-bound) solves. This option stops the optimization as soon as the upper bound (for a maximization) is <= r. So if you set r to the best optimal objective value seen so far, then when the loop tries other values of c, r, N_HC, r_HV, the optimization will be stopped as soon as the MIP algorithm proves that the objective cannot be improved using those values.

However, when I implement this idea using Gurobi, I get error messages indicating that there may be a bug. I am reporting this problem now, and hopefully it will be fixed soon; I will post an update here when there is a fix available. Until then, your best bet may be to just wait for all 7200 problems to solve.

Currently Gurobi is the only solver that uses a MIP approach to solve non-convex continuous quadratic problems to global optimality, and that has an option like bestbndstop.

See also my follow-up in the next message.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Fri, Nov 12, 2021 at 2:23 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Sir,

I would like to know the optimal value (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Is there any possibility of solving with integer variables the value of c, r, N_HC, and r_HV without using the for loop? Can you please suggest to me the way to greatly reduce the Gurobi solving time? I need your help please.

Sincerely,
Leon
On Tue, Nov 9, 2021 at 1:42 AM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
In the model, I would like to consider -- c, r, N_HC, and r_HV -- as variables of the problem and solve to know the optimal value of my model (the optimal profit of the objective function, and the optimal value of the variables) for only the choice of variables that is best. I only need to know the optimal value for the choice that is best. Please suggest to me the way to greatly reduce the Gurobi solving time.

I also have Minos solver and cplex if any combination can work better than gurobi, I can consider it.

On Mon, Nov 8, 2021 at 8:37 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
It would be possible to make one or more of your four loop parameters -- c, r, N_HC, and r_HV -- into a variable of the problem, so that you would have a lot fewer problems to solve. However, because of the way that those parameters are used in the model, I expect that making even one of them into a variable would cause the resulting problems to be much harder to solve. Thus, I do not expect that this approach would be helpful.

I notice that you are asking Gurobi to solve every one of the 7200 problems to within the optimality tolerance. (By default, Gurobi stops when the gap between its lower and upper bounds on the objective differ by 0.01% or less.) Do you need to know the optimal value of your model for every one of the 7200 different choices of the parameters, or is it enough to know the optimal value for the choice that is best? If you say that you only need to know the optimal value for the choice that is the best, then I can suggest a way to greatly reduce the Gurobi solving time.


--
Robert Fourer
am...@googlegroups.com

Matts Davids

unread,
Nov 25, 2021, 2:59:22 PM11/25/21
to am...@googlegroups.com
Thank you for the feedback.
In this case, can I say that my formulated problem is wrong?

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.

AMPL Google Group

unread,
Nov 27, 2021, 12:44:36 PM11/27/21
to AMPL Modeling Language
Since I am not familiar with your application, I cannot say whether your formulation is right or wrong. My comments only imply that your formulation is too hard to solve, using AMPL and good general-purpose solvers. Thus you will need to look for an improved approach.

One thing you can do is to reduce the amount of time that the solver spends on the 7200 different cases. I had thought to use Gurobi's bestbndstop=r option, but I found that it is not always working properly. It will be fixed eventually, but meanwhile another approach you can take is to solve each case first with Gurobi options nodelim=1 and bestbound=1. Then Gurobi will stop after 1 search node and will return an upper bound on the objective value in obj.bestbound. If this upper bound is <= the best objective function value you have seen so far, then you know that the case you are currently solving cannot be the optimal one, and you can go on to the next case. If the upper bound is > the best objective function value seen so far, then you do need to remove the nodelim=1 option and solve to optimality, but that might not happen very often.

Applying this approach to the example that you gave, I found that the first case was the optimal one, and only 5 other cases needed to be solved to optimality. The entire run took less than an hour. I used the attached run file, which you could modify for your needs.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Thu, Nov 25, 2021 at 7:59 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Thank you for the feedback.
In this case, can I say that my formulated problem is wrong?

On Mon, Nov 15, 2021 at 3:23 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Also as I mentioned previously, it would be possible to make one or more of your four loop parameters -- c, r, N_HC, and r_HV -- into a variable of the problem, so that you would have fewer problems to solve. However, because of the way that those parameters are used in the model, making them into variables would cause the resulting problems to be much harder to solve. Thus, the overall solution time might not be reduced.

For example, you could consider making N_HC into a variable:

   var N_HC integer >= 1, <= N_HC_Max;

But then there are two parameters (Start_hv and theta_hv) that depend on N_HC, and that will also have to be changed into variables. Also N_HC appears in the objective function. But the real trouble is that N_HC appears in many constraints in contexts where a variable is not permitted. For example,

  subject to pzero_HV{t in TT}:
     P_0_hv[t] = (sum{i in 0..(N_HC-1)}((((N_HC*Start_hv[t])^i)/(fact[i]))) +
     (((N_HC*Start_hv[t])^N_HC)/(fact[N_HC]))*
     ((1 - (Start_hv[t]*(m_hv[t]^(r_HV))))/(1-Start_hv[t])) )^-1;

You cannot write "sum{i in 0..(N_HC-1)}" where N_HC is a variable, or fact[N_HC] where fact is a param and N_HC is a variable; also Gurobi will not accept a highly nonlinear expression like ((N_HC*Start_hv[t])^N_HC) where N_HC is a variable. So you can see that your model would require significant reformulations to permit N_HC to be a variable, and then it could happen that the reformulated model is much more difficult to solve.


--
Robert Fourer
am...@googlegroups.com
Foodmarket4.dat
Foodmarket4.mod
Foodmarket4.run

Matts Davids

unread,
Jan 16, 2022, 7:14:02 AM1/16/22
to am...@googlegroups.com
Hello Robert,

Thank you so much for your help. I have tried to run the problem. The program is running and shows many solutions. How can I know the optimal case? I don't understand well what you mean by a case in your previous email. 
Attached are both the current model and screenshots of the last page of the first and last pages of the displayed results.

Sincerely yours,
Davids

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
First page.JPG
Last page.JPG
Foodmarket5.run
Foodmarket5.dat
Foodmarket5.mod

AMPL Google Group

unread,
Jan 17, 2022, 3:56:59 PM1/17/22
to AMPL Modeling Language
Each different combination of cval in 2..C_Max, rval in 1..R_Max, N_HC_val in 2..N_HC_Max, and r_HV_val in 1..R_HV_Max is one case. So, each pass through your for-loop solves for one case. The optimal case is the one that gives the best objective value.


--
Robert Fourer
am...@googlegroups.com
{#HS:1674140037-106816#}
On Sun, Jan 16, 2022 at 12:14 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
Hello Robert,

Thank you so much for your help. I have tried to run the problem. The program is running and shows many solutions. How can I know the optimal case? I don't understand well what you mean by a case in your previous email.
Attached are both the current model and screenshots of the last page of the first and last pages of the displayed results.

Sincerely yours,
Davids

On Sat, Nov 27, 2021 at 5:44 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Since I am not familiar with your application, I cannot say whether your formulation is right or wrong. My comments only imply that your formulation is too hard to solve, using AMPL and good general-purpose solvers. Thus you will need to look for an improved approach.

One thing you can do is to reduce the amount of time that the solver spends on the 7200 different cases. I had thought to use Gurobi's bestbndstop=r option, but I found that it is not always working properly. It will be fixed eventually, but meanwhile another approach you can take is to solve each case first with Gurobi options nodelim=1 and bestbound=1. Then Gurobi will stop after 1 search node and will return an upper bound on the objective value in obj.bestbound. If this upper bound is <= the best objective function value you have seen so far, then you know that the case you are currently solving cannot be the optimal one, and you can go on to the next case. If the upper bound is > the best objective function value seen so far, then you do need to remove the nodelim=1 option and solve to optimality, but that might not happen very often.

Applying this approach to the example that you gave, I found that the first case was the optimal one, and only 5 other cases needed to be solved to optimality. The entire run took less than an hour. I used the attached run file, which you could modify for your needs.


--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages