ConstraintInstance

class ConstraintInstance

The ConstraintInstance object stores the information regarding a specific instance of a costraint. The instances can be accessed through the function Constraint.get of the parent entity.

body()

classmethod ConstraintInstance.body()

Syntax

v = body()

Description

v = body() Get the current value of the constraint’s body.

Output Arguments

v

The current body of the constraint.

Example

Create a constraint c (using AMPL.eval), get an instance and display its body.

ampl.eval('var x{i in 1..2} := i*0.9;');
ampl.eval('c{i in 1..2} : 0<= x[i] <= 5;');
c1 = ampl.getConstraint('c').get(1);
c1.body

gives:

ans =
0.9000

dual

classmethod ConstraintInstance.dual()

Syntax

v = dual

Description

dual Get the current value of the constraint’s dual variable.

Output Arguments

v

The value of the dual variable corresponding to the constraint

Example

Create a constraint c (using AMPL.eval), get an instance and display its dual value.

ampl.eval('var x{i in 1..2} := i*0.9;');
ampl.eval('c{i in 1..2} : 0<= x[i] <= 5;');
c1 = ampl.getConstraint('c').get(1);
c1.dual

gives:

ans = 0

setDual(v)

classmethod Constraint.setDual()

Syntax

setDual(v)

Description

setDual(v) Assigns the specified value to the dual variable. Valid only for scalar constraints. Equivalent to the AMPL code:

var x;
c: x<=5;
let c := v;

Input Arguments

v

The value to be assigned

Example

Create a constraint c and sets its dual value. We have to switch off AMPL presolve abilities to see the effect consistently.

ampl.setBoolOption('presolve', 0)
ampl.eval('var x;');
ampl.eval('c: x <= 20;');
c = ampl.getConstraint('c');
c.setDual(4);
c.dual

gives:

ans =
  4

lb

classmethod ConstraintInstance.lb()

Syntax

v = lb

Description

lb Access the current lower bound of the constraint.

Output Arguments

v

The lower bound of the constraint.

Example

Create a constraint c (using AMPL.eval), get an instance and display its lower bound.

ampl.eval('var x{i in 1..2} := i*0.9;');
ampl.eval('c{i in 1..2} : 0<= x[i] <= 5;');
c1 = ampl.getConstraint('c').get(1);
c1.lb

gives:

ans = 0

ub

classmethod ConstraintInstance.ub()

Syntax

v = ub

Description

dual Access the current upper bound of the constraint.

Output Arguments

v

The upper bound of the constraint

Example

Create a constraint c (using AMPL.eval), get an instance and display its upper bound.

ampl.eval('var x{i in 1..2} := i*0.9;');
ampl.eval('c{i in 1..2} : 0<= x[i] <= 5;');
c1 = ampl.getConstraint('c').get(1);
c1.ub

gives:

ans = 5

drop

classmethod ConstraintInstance.drop()

Syntax

drop

Description

drop Drop this instances of the constraint, corresponding to the AMPL code drop constraintname[index];.

Example

Create an indexed constraint c (using AMPL.eval) and drop one instance:

  ampl.eval('var x{1..3}<=4;');
  ampl.eval('maximize z: sum{i in 1..3} x[i];');
  ampl.eval('c {i in 1..3} : x[i] <= i;');
  x = ampl.getVariable('x');
  ampl.solve;
  x.display
  ampl.getConstraint('c').get(2).drop
  ampl.solve;
  x.display

gives::

  ans =
  x [*] :=
  1  1
  2  2
  3  3
  ;

  ans =
  x [*] :=
  1  1
  2  4
  3  3
  ;

restore

classmethod ConstraintInstance.restore()

Syntax

restore

Description

restore Restore this instance of the constraint

Example

Create a constraint c, get an instance (c2), drop it and restore it, solving and displaying the values of the variables involved.

ampl.eval('var x{1..3}<=4;');
ampl.eval('maximize z: sum{i in 1..3} x[i];');
ampl.eval('c {i in 1..3} : x[i] <= i;');
c2 = ampl.getConstraint('c').get(2);
x = ampl.getVariable('x');

c2.drop;
ampl.solve;
x.display

c2.restore;
ampl.solve;
x.display

gives:

x [*] :=
1  1
2  4
3  3
;


ans =

x [*] :=
1  1
2  2
3  3
;