[AMPL 2862] Redefining a variables

View: New views
5 Messages — Rating Filter:   Alert me  

[AMPL 2862] Redefining a variables

by A. Ismael F. Vaz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear All,

I am attaching a model file with a multi-objective problem. Due to its
complexity I need to define several layers of variables and then expect AMPL
to replace (substitute) them in the final problem.

The let command is just assigning to the variables a value obtained from the
previous variables, but that not what I want.

Could you please help?

Best regards,
Ismael Vaz
University of Minho
Portugal

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---



WFG1.mod (2K) Download Attachment

[AMPL 2863] Re: Redefining a variables

by A. Ismael F. Vaz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear All,

A possible way is to define the variables relation as constraints and to use
the "option substout 1;", as shown in the attached file. But I wonder if
there is a easier way.

Best,
Ismael

> -----Original Message-----
> From: ampl@... [mailto:ampl@...] On
> Behalf Of A. Ismael F. Vaz
> Sent: segunda-feira, 5 de Outubro de 2009 2:41
> To: ampl@...
> Subject: [AMPL 2862] Redefining a variables
>
> Dear All,
>
> I am attaching a model file with a multi-objective problem.
> Due to its complexity I need to define several layers of
> variables and then expect AMPL to replace (substitute) them
> in the final problem.
>
> The let command is just assigning to the variables a value
> obtained from the previous variables, but that not what I want.
>
> Could you please help?
>
> Best regards,
> Ismael Vaz
> University of Minho
> Portugal
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---



WFG1Try.mod (2K) Download Attachment

[AMPL 2864] Re: Redefining a variable

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Ismael,

Instead of writing

   var t1{1..n};
   subject to first1{i in 1..k}:
      t1[i] = y[i];
   subject to first2{i in k+1..n}:
      t1[i] = abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);

you could consider declaring

   var t1 {i in 1..n} =
      if i <= k then y[i]
      else abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);

The same approach could be used for each of the other variables, as long as
the expression on the right of the = only involves previously defined
variables.  (Of course, you would need a solver that can deal with nonsmooth
functions like abs and floor.)

Bob Fourer
4er@...


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of A. Ismael F. Vaz
> Sent: Monday, October 05, 2009 10:26 AM
> To: ampl@...
> Subject: [AMPL 2863] Re: Redefining a variables
>
> Dear All,
>
> A possible way is to define the variables relation as constraints and to
> use the "option substout 1;", as shown in the attached file. But I wonder
> if there is a easier way.
>
> Best,
> Ismael
>
> > -----Original Message-----
> > From: ampl@... [mailto:ampl@...] On
> > Behalf Of A. Ismael F. Vaz
> > Sent: segunda-feira, 5 de Outubro de 2009 2:41
> > To: ampl@...
> > Subject: [AMPL 2862] Redefining a variables
> >
> > Dear All,
> >
> > I am attaching a model file with a multi-objective problem.
> > Due to its complexity I need to define several layers of
> > variables and then expect AMPL to replace (substitute) them
> > in the final problem.
> >
> > The let command is just assigning to the variables a value
> > obtained from the previous variables, but that not what I want.
> >
> > Could you please help?
> >
> > Best regards,
> > Ismael Vaz
> > University of Minho
> > Portugal
> >
> > >
> >
>



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2865] Re: Redefining a variable

by A. Ismael F. Vaz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Dear Bob,

Thanks for the reply. I was about to swear that this approach did not work
for me in the past.

In what cases is AMPL passing the if statement to the solver? For example:

var x;
var y;
var z = if x<y then x else y;


I am indeed developing a derivative-free solver for multi-objective
optimization and I am collecting some test problems.

Best,
Ismael

 

> -----Original Message-----
> From: Robert Fourer [mailto:4er@...]
> Sent: segunda-feira, 5 de Outubro de 2009 17:02
> To: ampl@...; 'A. Ismael F. Vaz'
> Subject: RE: [AMPL 2863] Re: Redefining a variable
>
> Ismael,
>
> Instead of writing
>
>    var t1{1..n};
>    subject to first1{i in 1..k}:
>       t1[i] = y[i];
>    subject to first2{i in k+1..n}:
>       t1[i] = abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);
>
> you could consider declaring
>
>    var t1 {i in 1..n} =
>       if i <= k then y[i]
>       else abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);
>
> The same approach could be used for each of the other
> variables, as long as the expression on the right of the =
> only involves previously defined variables.  (Of course, you
> would need a solver that can deal with nonsmooth functions
> like abs and floor.)
>
> Bob Fourer
> 4er@...
>
>
> > -----Original Message-----
> > From: ampl@... [mailto:ampl@...]
> On Behalf
> > Of A. Ismael F. Vaz
> > Sent: Monday, October 05, 2009 10:26 AM
> > To: ampl@...
> > Subject: [AMPL 2863] Re: Redefining a variables
> >
> > Dear All,
> >
> > A possible way is to define the variables relation as
> constraints and
> > to use the "option substout 1;", as shown in the attached
> file. But I
> > wonder if there is a easier way.
> >
> > Best,
> > Ismael
> >
> > > -----Original Message-----
> > > From: ampl@...
> [mailto:ampl@...] On Behalf
> > > Of A. Ismael F. Vaz
> > > Sent: segunda-feira, 5 de Outubro de 2009 2:41
> > > To: ampl@...
> > > Subject: [AMPL 2862] Redefining a variables
> > >
> > > Dear All,
> > >
> > > I am attaching a model file with a multi-objective problem.
> > > Due to its complexity I need to define several layers of
> variables
> > > and then expect AMPL to replace (substitute) them in the final
> > > problem.
> > >
> > > The let command is just assigning to the variables a
> value obtained
> > > from the previous variables, but that not what I want.
> > >
> > > Could you please help?
> > >
> > > Best regards,
> > > Ismael Vaz
> > > University of Minho
> > > Portugal
> > >
> > > >
> > >
> >
>
>
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2869] Re: Redefining a variable

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Dear Ismael,

Where a variable is defined by "var z = if ... then ... else ... ;", if
there are variables between "if" and "then", then the whole "if" expression
is sent to the solver.  But if the expression between "if" and "then"
contains only sets and parameters, AMPL evaluates that expression at the
time of problem generation and (depending on whether it evaluates to true or
false) passes only the expression following "then" or the expression
following "else" to the solver.

So in the example that I gave with "var t1 {i in 1..n} = if i <= k ..." as
long as k is a parameter, you should not expect the solver to see the "if"
expression.  But in your example with "var z = if x<y then ..." since x and
y are variables the "if" expression will be passed to the solver.

Bob Fourer
4er@...


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of A. Ismael F. Vaz [aivaz@...]
> Sent: Monday, October 05, 2009 12:05 PM
> To: ampl@...
> Subject: [AMPL 2865] Re: Redefining a variable
>
>
> Dear Bob,
>
> Thanks for the reply. I was about to swear that this approach did not work
> for me in the past.
>
> In what cases is AMPL passing the if statement to the solver? For example:
>
> var x;
> var y;
> var z = if x<y then x else y;
>
>
> I am indeed developing a derivative-free solver for multi-objective
> optimization and I am collecting some test problems.
>
> Best,
> Ismael
>
>
>
> > -----Original Message-----
> > From: Robert Fourer [mailto:4er@...]
> > Sent: segunda-feira, 5 de Outubro de 2009 17:02
> > To: ampl@...; 'A. Ismael F. Vaz'
> > Subject: RE: [AMPL 2863] Re: Redefining a variable
> >
> > Ismael,
> >
> > Instead of writing
> >
> >    var t1{1..n};
> >    subject to first1{i in 1..k}:
> >       t1[i] = y[i];
> >    subject to first2{i in k+1..n}:
> >       t1[i] = abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);
> >
> > you could consider declaring
> >
> >    var t1 {i in 1..n} =
> >       if i <= k then y[i]
> >       else abs(y[i]-0.35)/abs(floor(0.35-y[i])+0.35);
> >
> > The same approach could be used for each of the other
> > variables, as long as the expression on the right of the =
> > only involves previously defined variables.  (Of course, you
> > would need a solver that can deal with nonsmooth functions
> > like abs and floor.)
> >
> > Bob Fourer
> > 4er@...
> >
> >
> > > -----Original Message-----
> > > From: ampl@... [mailto:ampl@...]
> > On Behalf
> > > Of A. Ismael F. Vaz
> > > Sent: Monday, October 05, 2009 10:26 AM
> > > To: ampl@...
> > > Subject: [AMPL 2863] Re: Redefining a variables
> > >
> > > Dear All,
> > >
> > > A possible way is to define the variables relation as
> > constraints and
> > > to use the "option substout 1;", as shown in the attached
> > file. But I
> > > wonder if there is a easier way.
> > >
> > > Best,
> > > Ismael
> > >
> > > > -----Original Message-----
> > > > From: ampl@...
> > [mailto:ampl@...] On Behalf
> > > > Of A. Ismael F. Vaz
> > > > Sent: segunda-feira, 5 de Outubro de 2009 2:41
> > > > To: ampl@...
> > > > Subject: [AMPL 2862] Redefining a variables
> > > >
> > > > Dear All,
> > > >
> > > > I am attaching a model file with a multi-objective problem.
> > > > Due to its complexity I need to define several layers of
> > variables
> > > > and then expect AMPL to replace (substitute) them in the final
> > > > problem.
> > > >
> > > > The let command is just assigning to the variables a
> > value obtained
> > > > from the previous variables, but that not what I want.
> > > >
> > > > Could you please help?
> > > >
> > > > Best regards,
> > > > Ismael Vaz
> > > > University of Minho
> > > > Portugal
> > > >
> > > > >
> > > >
> > >
> >
> >
> >
>



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---