Search code examples
ampl

declare default value for variables in ampl


Now I have variable set x in my ampl model, and I want to define a default value for each x.

set N := 1..10;
var x {i in N} default 0;

If I build the model like this, the initial value of all x would be set as 0. How can I set different value for each x, like [0,0,0,0,0,1,1,1,1,1]?


Solution

  • If you just want to change some parts of x to a non-default value, this is easy to do. For example:

    var x{i in N} default 0;
    let{i in 6..10} x[i] := 1;
    

    I'm not aware of any way to have more than one default value for different elements of a var.