简体   繁体   中英

How to get the required 2D array from the multiple 1D arrays taking into consideration the below notes?

I have an output of 4 decision variables arrays i want to represent them in a 2D array. I have no of beams with no of channels & start channel (for each beam) to be distributed over all 2D array (the N rows (rows)* N channels(columns)).

/*

taking into considration 
(1) Number of beams in each row 
(2) Number of channels for each beam 
(3) Channel location in the row
*/
int Nbeams=21;      //to be distributed on the 2D array
int Nchannels=16;   //No of columns 
int Nrows=4;        //No of rows

dvar int No_beams_in_each_row[rows]=[6,6,6,4];
dvar int beam_firstchannel[beams]=[1,3,5,7,9,15,1,3,5,7,9,15,1,3,5,7,9,15,1,5,9,13];
dvar int beam_nomusedchannel[beams]=[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4];
dvar int beam_row[beams]=[1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4]; 
*/

//The below code take in considration only number of beams in each row 
  int isBeamThere[i in rows][j in 1..Nchannels]=(j<=No_beam_in_each_row[i]); 

  execute
  {
  writeln("No_beam_in_each_row=",No_beam_in_each_row);
  writeln("isBeamThere=",isBeamThere);  
  }
  //which gives 
  No_beam_in_each_row= [6 6 6 4]
  isBeamThere= [[1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
                [1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
                [1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0]
                [1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]]

/* But i want to take in consideration no of channels for each beam and the location of channels 
   for each beam
   for example the first three rows each one has 6 beams and each beam has 2 channels and the last 
   row has 4 beams each one has 4 channels with considering number and location of channels for 
    each beam so we will have 

isBeamThere = 

[[1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1] // beacuse the last beam in the first row occup channel 15&16
 [1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1]
 [1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1]
 [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]

How to get this 2D array from the above 1 D arrays??

I would suggest scripting to do that.

int Nbeams=22;      //to be distributed on the 2D array
int Nchannels=16;   //No of columns 
int Nrows=4;        //No of rows
range rows=1..Nrows;
range beams=1..Nbeams;

int sol1[beams]=[1,3,5,7,9,15,1,3,5,7,9,15,1,3,5,7,9,15,1,5,9,13];
int sol2[beams]=[2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4];
int sol3[beams]=[1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4]; 

dvar int beam_firstchannel[beams];
dvar int beam_nomusedchannel[beams];
dvar int beam_row[beams];


subject to
{
  forall(i in beams) beam_firstchannel[i]==sol1[i];
  forall(i in beams) beam_nomusedchannel[i]==sol2[i];
  forall(i in beams) beam_row[i]==sol3[i];
}

int isBeamThere[i in rows][j in 1..Nchannels];

execute compute
{
  for(var i in beams)
    for(var k=0;k<beam_nomusedchannel[i];k++)
    {
     
     isBeamThere[beam_row[i]][beam_firstchannel[i]+k]=1;
    }     
}

execute
{
 
  writeln("isBeamThere=",isBeamThere);
}

// Use the Gantt    
tuple sequence_like {
   int start;
   int end;
   string label;
   int type;
 };   
 
{sequence_like} array2[i in rows] = {<j-1,j," ",isBeamThere[i][j]> | j in 1..Nchannels};

execute
{
 array2; 
}

gives

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM