0

How to write the following constrains in cplex (the part in subject to) assuming that i have the results of the first two decision variables as shown below

     int Nbeams=8;
     int Nchannels=16;
     int Nrows=2;          // I have my code to make each 

     range beams=1..Nbeams;
     range channels=1.. Nchannels; 
     range rows=1..Nrows;
     
     dvar int first_beam_in_each_row [rows]      in (1..Nbeams);       
     dvar int beam_nomchannel[beams]             in   (channels);
     dvar int beam_firstchannel[beams]           in   (channels);

/*
assume we have the output of:
dvar int first_beam_in_each_row [rows]=[1,5]
dvar int beam_nomchannel[beams]=[2,2,2,2,2,2,2,2];

How to write the next part????
*/

Subject to 
{
forall (i in beams)
while or if 
i= value of first_beam_in_each_row [rows] // while i = 1 , 5 
then
value of beam_firstchannel[beams]=1;
else                                       //while i = 2,3,4,6,7,8
value of beam_firstchannel[beams]=value of previous beam_firstchannel[beams]+ value of previos beam_nomchannel[beams];                  // beam_firstchannel[3]=beam_firstchannel[2]+beam_nomchannel[2]
}

1
  • @Alex Fleischer Commented Dec 6, 2022 at 3:23

1 Answer 1

2

You could start with the following that works fine as far as syntax is involved.

int Nbeams=8;
     int Nchannels=16;
     int Nrows=2;          // I have my code to make each 

     range beams=1..Nbeams;
     range channels=1.. Nchannels; 
     range rows=1..Nrows;
     
     dvar int first_beam_in_each_row [rows]      in (1..Nbeams);       
     dvar int beam_nomchannel[beams]             in   (channels);
     dvar int beam_firstchannel[beams]           in   (channels);



subject to 
{

forall(j in rows)
  {
forall (i in beams: i in 1..5) 
(first_beam_in_each_row [j]==i) => (beam_firstchannel[i]==1);
  
forall (i in beams: i in {2,3,4,6,7,8})  
(first_beam_in_each_row [j]!=i) => (beam_firstchannel[i]==beam_firstchannel[i-1]+ beam_nomchannel[i-1]);   
  

}

}

and with regards to your later question

int Nbeams=8;
     int Nchannels=16;
     int Nrows=2;          // I have my code to make each 

     range beams=1..Nbeams;
     range channels=1.. Nchannels; 
     range rows=1..Nrows;
     
     dvar int first_beam_in_each_row [rows]      in (1..Nbeams);       
     dvar int beam_nomchannel[beams]             in   (channels);
     dvar int beam_firstchannel[beams]           in   (channels);



subject to 
{

forall(j in rows )   {    
 forall (i in beams)    
   ((first_beam_in_each_row [j]==i) && (i<=first_beam_in_each_row[j]))
   => (beam_firstchannel[i]==1);     
 forall (i in beams:i>=2)     
       ((first_beam_in_each_row [j]!=i) && (i<=Nbeams-first_beam_in_each_row[j]))=> 
       (beam_firstchannel[i]==beam_firstchannel[i-1]+ beam_nomchannel[i-1]);    }   
}

works fine

NB: Not good practice to go on with a discussion within stackoverflow. Much better to ask a new question

Many ways to learn more about CPLEX in

https://www.linkedin.com/pulse/low-barrier-entry-optimization-through-cplex-alex-fleischer/

Sign up to request clarification or add additional context in comments.

4 Comments

forall (i in beams: i in 1..5) // i want to write it forall (i in beams: i in beams) forall (i in beams: i in {2,3,4,6,7,8}) // i want to write it forall (i in beams: i beams ) How to write this because the beams number is very big?
beams is very large number so to indicate each beam like i in {2.3.4.6.7.8} in forall is not feasible so how to write it in another way ?
forall (i in beams: i in subset) where you compute subset as you need
forall(j in rows ) { forall (i in beams: i in first_beam_in_each_row[j] ) (first_beam_in_each_row [j]==i) => (beam_firstchannel[i]==1); forall (i in beams: i in 1..(Nbeams-first_beam_in_each_row[j] )) (first_beam_in_each_row [j]!=i) => (beam_firstchannel[i]==beam_firstchannel[i-1]+ beam_nomusedchannel[i-1]); } } I have tried this but gives me error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.