繁体   English   中英

考虑到以下注意事项,如何从多个一维数组中获取所需的二维数组?

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

我有 4 个决策变量数组的输出,我想在二维数组中表示它们。 我没有没有通道的光束和开始通道(对于每个光束)分布在所有 2D 阵列(N 行(行)* N 通道(列))。

/*

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

如何从上面的一维数组中得到这个二维数组??

我建议编写脚本来做到这一点。

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

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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