MO MO MA
MO MO MA

Reputation: 49

How write this constrains in cplex?

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]
}

Upvotes: 0

Views: 66

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10062

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/

Upvotes: 1

Related Questions