![](/img/trans.png)
[英]How to compile the below 4 decision variable arrays in one array using tuple and to be seen in the OPL IDE as a 2D view?
[英]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.