[AMPL 2624] Defining a variable domain

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

[AMPL 2624] Defining a variable domain

by Amadeus-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi all,

I have two questions.

1. In this expression, I would like to allow the variables A to have
values of either -1 or 1.

var A{i in 1..10} integer >= -1.0, <= 1.0;

This would definitely not work because A \in {-1,0,1}
How can I do it?


2.  Assume that B is a variable defined in 4 dimension discrete space.
Specifically, B \in {-1,1}^4
I would like to restrict its domain to (1,1,1,1) (1,1,-1,-1) and
(-1,-1,-1,-1).
Is there any valid AMPL expression for this?

Thanks!
I appreciate your help.

--~--~---------~--~----~------------~-------~--~----~
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 2625] Re: Defining a variable domain

by Paul A. Rubin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



On Jul 5, 11:45 pm, Amadeus <soom...@...> wrote:
>
> 1. In this expression, I would like to allow the variables A to have
> values of either -1 or 1.
>
> var A{i in 1..10} integer >= -1.0, <= 1.0;
>
> This would definitely not work because A \in {-1,0,1}
> How can I do it?

var AA {i in 1..10} binary;
var A {i in 1..10} = 2*AA[i] - 1;

> 2.  Assume that B is a variable defined in 4 dimension discrete space.
> Specifically, B \in {-1,1}^4
> I would like to restrict its domain to (1,1,1,1) (1,1,-1,-1) and
> (-1,-1,-1,-1).
> Is there any valid AMPL expression for this?

var BB {i in 1..4} binary;
var B {i in 1..4} = 2*BB[i] - 1;
s.t. limit1: B[1] - B[2] + B[3] - B[4] = 0;
s.t. limit2: -B[1] - B[2] + B[3] + B[4] <= 2;
s.t. limit3: -B[1] + B[2] + B[3] - B[4] <= 2;
s.t. limit4: B[1] - B[2] - B[3] + B[4] <= 2;
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---