AMPL PLF (piecewise linear function) as a CC (convex combination) modelling!

Hi,

I am trying the following constraints to build in AMPL for Convex combination modelling of a piecewise linear function:

# Parameters
param K;                        # Number of k values
param Z;                        # Number of z values
param N;                        # Number of n values - intervals of divisions of plf

param xbar{1..N};         # x̄[n] values
param ybar{1..N};         # ȳ[n] values

# Variables
var lambda{1..N, 1..Z, 1..K} >= 0;          # λ_k values, non-negative
var delta{1..N-1, 1..Z, 1..K} binary;       # δ_s values, binary for 1 to K-1

# Constraints
subject to constraint_x {z in 1..Z, k in 1..K}: 
    sum{n in 1..N} xbar[n] * lambda[n, z, k] = x[z, k]; 

subject to constraint_y {z in 1..Z, k in 1..K}: 
    sum{n in 1..N} ybar[n] * lambda[n, z, k] = y[z, k]; 

subject to constraint_sum_lambda{z in 1..Z, k in 1..K}: 
    sum{n in 1..N} lambda[n, z, k] = 1;             

# Lambda constraints based on delta
subject to lambda_n1{z in 1..Z, k in 1..K}: 
    lambda[1, z, k] <= delta[1, z, k];

subject to lambda_n2_to_N1 {n in 2..N-1, z in 1..Z, k in 1..K}: 
    lambda[n, z, k] <= delta[n-1, z, k] + delta[n, z, k];

subject to lambda_N{z in 1..Z, k in 1..K}: 
    lambda[N, z, k] <= delta[N-1, z, k];

# Constraint for delta sum
subject to constraint_delta_sum{z in 1..Z, k in 1..K}: 
    sum{s in 1..N-1} delta[s, z, k] = 1;

# Objective
maximize obj: sum{z in 1..Z, k in 1..K} y[z, k];

But, I am keep getting this error:

subject to constraint_sum_lambda{z in 1…Z, k in 1…K}:
sum{n in 1…N} lambda[n, z, k] = 1; I am getting this error: all variables eliminated, but lower bound = 1 > 0

Although I am able to build up these constraints in Gurobi in Python platform, and it’s working!

I want to know how can I get it working in AMPL?

This is an issue with solving the problem, rather than with building the constraints:

By analyzing the constraints of your problem, AMPL’s presolve phase can often determine tighter bounds for the variables. Sometimes it determines a lower bound and an upper bound that are equal; in that case, it can fix the variable at the determined bound (and can eliminate the variable from the problem). In your case, it happened that some constraints had all of their variables fixed, and the values they were fixed at did not satisfy the constraint. This proves that no feasible solution to your constraints is possible, and as a result, AMPL did not send your problem to the solver.

In your particular example, where

all variables eliminated, but lower bound = 1 > 0

the most likely cause is that, for some values of z and k, all the variables in constraint_sum_lambda[z,k] were fixed at zero, and thus their sum could not be 1.

To learn more, you can use AMPL’s “expand” command to view constraints mentioned in the presolve messages, and you can use AMPL’s “display” command to see the bounds deduced for variables in those constraints. To get more specific advice, however, you’ll need to provide a complete model and data.

In general, this kind of situation is caused by a model or data error, but there is no simple way to automatically determine the cause. You will need to study your model and data to learn why this is happening.

If you like, you can turn off AMPL’s presolve by setting

option presolve 0;

Then the problem will be sent to Gurobi, which should give you a “no feasible solution” result.

1 Like

Thanks for the prompt reply.

I have relaxed my fixed variable by assigning it as:
subject to con1 {z in Z}:
sum{d in D} x[z, d, 0] = eps;

whereas:

param eps := 0.00000001;

Now, I am getting this error:

    presolve: constraint constraint_sum_law[40,0] cannot hold:
            body >= 1 cannot be <= 4.14996e-07; difference = 1
    presolve: constraint constraint_sum_law[39,0] cannot hold:
            body >= 1 cannot be <= 4.14996e-07; difference = 1
    presolve: constraint constraint_sum_law[38,0] cannot hold:
            body >= 1 cannot be <= 4.14996e-07; difference = 1
    presolve: constraint constraint_sum_law[37,0] cannot hold:
            body >= 1 cannot be <= 4.14996e-07; difference = 1
    presolve: constraint constraint_sum_law[36,0] cannot hold:
            body >= 1 cannot be <= 4.14996e-07; difference = 1
    35 presolve messages suppressed.

I tried making the presolve = 0 and I get infeasible, and model interpretation helps nothing, since it is solvable by other compiler. There must be something wrong in terms of implementation of the modelling part?

If the solver reported “optimal solution” when you wrote the model some other way, but it reports “no feasible solution” when you write it in AMPL, then your AMPL formulation must be different somehow. And since there are supposed to be feasible solutions, your AMPL version must have some errors in it.

With only the limited information you have provided, however, it is not possible to provide much useful advice. While you did post a model previously, it has changed. To get more help, I suggest posting the complete current version of your model, and also the data that you used.

1 Like