Constraint _scon[1] is not convex quadratic since it is an equality constraint.

3,659 views
Skip to first unread message

hessam

unread,
Jun 24, 2010, 2:00:46 PM6/24/10
to AMPL Modeling Language
Hi everyone,

In my code I have 4 arrays (a,b,c,x) and I have a condition which
looks like:

if (x[i]==1) then c[i]=a[i]*b[i]
else c[i]=0

Then I want to minimize summation of the elements of array c. so I
wrote it like this in AMPL

subject to const {i in 1..n} : c[i]=a[i]*b[i]*x[i]
minimize obj: sum{i in 1..n} c[i]

But it seems CPLEX cannot handle three multiplication and it gives the
error "Constraint _scon[1] is not convex quadratic since it is an
equality constraint.".

Is there any other way that I can have the same functionality in AMPL
for CPLEX??

Paul

unread,
Jun 24, 2010, 4:15:23 PM6/24/10
to AMPL Modeling Language
It would help if you indicated which things were binary variables,
which were integer variables, which were real variables and which were
parameters.

hessam

unread,
Jun 24, 2010, 4:50:51 PM6/24/10
to AMPL Modeling Language
all of them are variables (none of them are parameters). x is binary
variable and the other ones (a,b,c) are real variables.

Paul

unread,
Jun 24, 2010, 5:55:56 PM6/24/10
to AMPL Modeling Language
Then you can't use CPLEX. The constraint resolves to a quadratic
equality (c = a*b) when x = 1, and CPLEX will only accept convex
inequality constraints (convex function <= constant or concave
function >= constant).

/Paul

hessam

unread,
Jun 25, 2010, 8:29:52 PM6/25/10
to AMPL Modeling Language
So what if I change the constraint to:

subject to const {i in 1..n} : c[i]>=a[i]*b[i]*x[i]
minimize obj: sum{i in 1..n} c[i]

Which becomes like

if x[i]=0 then c[i]>=0
if x[i]=1 then c[i]>=a[i]*b[i]

since the objective is to minimize the summation over elements of c,
it will automatically choose 0 or (a[i]*b[i]). Am I right??

Paul

unread,
Jun 26, 2010, 10:16:08 AM6/26/10
to AMPL Modeling Language
On Jun 25, 8:29 pm, hessam <hessam.1...@gmail.com> wrote:
> So what if I change the constraint to:
>
> subject to const {i in 1..n} : c[i]>=a[i]*b[i]*x[i]
> minimize obj: sum{i in 1..n} c[i]
>

Problem 1: a*b*c is cubic, not quadratic.
Problem 2: g(a,b) = a*b is not a convex function.

So no, I don't think CPLEX will accept this either.

/Paul

kermani...@gmail.com

unread,
Dec 4, 2015, 10:23:09 AM12/4/15
to AMPL Modeling Language
Hi,
I have faced with a similar problem but I cannot understand the difference between these two options:
 
1 - This case works fine in ampl as it is defined as a predefined var:
var Unit_quality_mix_in{l in MassBalancesWithQuality, loc in ClustersOfLayer[l], u in MB_Units[l,loc], c in MBQ_components[l], t in Time: u in UnitsOfTime[t] and Units_flowrate_in[l,u,t] > 0} = 
if (Units_demand[l,u,t] > 0)
then (Unit_quality_mix_pf[l,loc,u,c,t]/Units_demand[l,u,t])
else (Units_quality_out[l,u,c,t]);

2 - But if I do the above as a constraint, (I would like to do it this way because I can have my constraint working also with glpsol, as glpsol doesn't have the predefined var) ampl give the error of not convex quadratic:
var Unit_quality_mix_in{l in MassBalancesWithQuality, loc in ClustersOfLayer[l], u in MB_Units[l,loc], c in MBQ_components[l], t in Time: u in UnitsOfTime[t] and Units_flowrate_in[l,u,t] > 0}; 
subject to cstr_Unit_quality_mix_in{l in MassBalancesWithQuality, loc in ClustersOfLayer[l], u in MB_Units[l,loc], c in MBQ_components[l], t in Time: u in UnitsOfTime[t] and Units_flowrate_in[l,u,t] > 0}:
Unit_quality_mix_in[l,loc,u,c,t] <= 
if (Units_demand[l,u,t] > 0)
then (Unit_quality_mix_pf[l,loc,u,c,t]/Units_demand[l,u,t])
else (Units_quality_out[l,u,c,t]);

Just to mention that "Unit_quality_mix_pf" and "Units_demand" are variables and "Units_quality_out" and "Units_flowrate_in" are parameters.

Why would ampl treat these two statements differently?

Thanks,
Maziar

Robert Fourer

unread,
Dec 4, 2015, 1:46:04 PM12/4/15
to am...@googlegroups.com
The "not convex quadratic" message does not come from AMPL, but from a solver that does not accept nonlinear constraints except for some kinds of convex quadratic ones. The solvers CPLEX, Gurobi, and Xpress are in this category. You will not see this error in case (1) however if the variables Unit_quality_mix_in do not appear anywhere in the objective or constraints -- since then AMPL does not send them to the solver.

If indeed Unit_quality_mix_in does not appear in any objective or constraint, then you should define it as a param rather than a variable. But then instead of Unit_quality_mix_pf[l,loc,u,c,t] and Units_demand[l,u,t] you will have to write Unit_quality_mix_pf[l,loc,u,c,t].val and Units_demand[l,u,t].val, since a param cannot be defined in terms of a variable but only in terms of the current value of the variable.

To get all of the features of AMPL with a free open-source solver, try using CBC from http://ampl.com/products/solvers/open-source/.

Bob Fourer
am...@googlegroups.com

=======

labhi...@gmail.com

unread,
Jun 19, 2017, 9:19:19 AM6/19/17
to AMPL Modeling Language
In ampl, it's saying constraint is not convex quadratic.
minimize Total_Cost= sum {i in Ps,j in Ts}(count[i] count[j](incost[i,j]*inflow[i,j])+(IsMade[i]*fixedcost[i])+(IsMade[j]fixedcost[j]) + sum {j in Ts,k in Ds} (count[j](outcost[j,k]*outflow[j,k])+ IsMade[j]*CDfixedcost[j]);

Is this logic correct if there is fixed cost for both ps and Ts;
Best Regards
Abhishek

Robert Fourer

unread,
Jun 20, 2017, 10:34:01 AM6/20/17
to am...@googlegroups.com
You have posted an objective function definition (minimize) but the error message is for a constraint. The error message is telling you that one of your constraints has a nonlinear term in it, and the solver (probably CPLEX or Gurobi or Xpress) cannot handle nonlinear = constraints.

It is not possible however to give advice about nonlinearities without knowing which items in your constraints are variables and which are parameters. To get more help you should post your whole model file, and also a copy of *all* though output from AMPL and the solver.

Bob Fourer
am...@googlegroups.com


-----Original Message-----
From: am...@googlegroups.com [mailto:am...@googlegroups.com] On Behalf Of labhi...@gmail.com
Sent: Monday, June 19, 2017 6:06 AM
To: AMPL Modeling Language
Reply all
Reply to author
Forward
0 new messages