🖥️ IT, 컴퓨터/🚀 최적화

[Cplex] 지역제한 P-median Cplex 코드 입력

김 홍시 2023. 3. 16.
반응형

지역제한 P-median

구 안에 하나씩 배정하는 문제

ex. 서울이라면 서울의 모든 구 안에 한 개의 시설을 배정하는 문제

 

 

mod

Customers : 수요지

Weight : 수요지의 수요량

WellfareCenters : 입지후보지

int P = ...;
{string} Customers = ...;
{int} WellfareCenters = ...;
int Weight[Customers] = ...;
float Distance[Customers][WellfareCenters] = ...;
{Point} Region = ...;

헷갈리지 않도록 Customer은 string으로 두었다.

//Variables
dvar boolean OpenWellfareCenters[WellfareCenters];
dvar boolean AllocToCustomer[Customers][WellfareCenters];
//Objective
minimize 
  sum( c in Customers , w in WellfareCenters ) 
    Weight[c]*Distance[c][w]*AllocToCustomer[c][w];

튜플을 하나 만들어서 그 안에 한 지역 안에 들어가야 하는 시설들을 써 준다.

ex. 한 지역에 3번, 4번, 5번의 시설이 들어온다면 <3,5>로 써줌

그렇게 구현하기 위해 아래와 같이 쓴다.

tuple Point {
  int x; 
  int y; 
}

 

//Constraints
subject to {
  forall( c in Customers )
    ctAlloc:
      sum( w in WellfareCenters ) 
        AllocToCustomer[c][w] == 1;

    ctOpen:
      sum( w in WellfareCenters ) 
        OpenWellfareCenters[w] == P;

  forall( point in Region )
    ctRegion:
      sum( w in point.x..point.y ) 
        OpenWellfareCenters[w] == 1;

  forall( c in Customers , w in WellfareCenters )
    ctAllocOpen:
      AllocToCustomer[c][w] <= OpenWellfareCenters[w];
}

 

 

 

 

 

dat

입지 시설 개수 P

P=15; //입지할 시설 개수 p

수요지 (362개)

Customers = {aware	,intention	,glide	,diagram	,magnetic	,harmful	,clear	,guarantee	,wave	,moving	,insert	,neglect	,beam	,linear	,sail	,annual	,argument	,tissue	,functional	,leadership	,indirect	,panic	,advice	,throne	,pitch	,anger	,night	,offensive	,sacrifice	,strong	,cheque	,qualification	,coat	,comedy	,devote	,jealous	,security	,absent	,pawn	,location	,hit	,arrow	,cope	,flourish	,version	,win	,established	,colony	,excitement	,entertain	,space	,shatter	,reverse	,reproduction	,hang	,high	,elite	,use	,fuss	,demonstrator	,sausage	,farewell	,lost	,embarrassment	,trunk	,neck	,decrease	,explode	,convince	,suitcase	,fair	,dangerous	,publish	,forward	,reach	,sum	,biscuit	,corpse	,parallel	,river	,alcohol	,chin	,sun	,debt	,routine	,chain	,scandal	,rage	,job	,pity	,revive	,impact	,bird	,wing	,waist	,embryo	,call	,second	,national	,consideration	,jest	,hike	,justify	,deteriorate	,fame	,obese	,formula	,activate	,lip	,dive	,pack	,border	,sun	,figure	,guideline	,bird	,digress	,advocate	,script	,address	,glasses	,unity	,import	,FALSE	,progress	,clay	,coast	,secure	,approval	,axis	,ally	,load	,amputate	,equinox	,horizon	,cinema	,devote	,acceptable	,viable	,surround	,initial	,referral	,sunrise	,reflect	,offender	,ideology	,memory	,pop	,squash	,misplace	,medieval	,foreigner	,crown	,despair	,function	,follow	,win	,beam	,descent	,sickness	,complete	,education	,measure	,mutter	,stuff	,inflate	,invite	,cultural	,promote	,hero	,suffer	,exit	,outlook	,predator	,island	,movement	,present	,nun	,position	,norm	,wake	,misery	,request	, qewrewrwe	,cycle	,sandwich	,module	,instinct	,dressing	,tender	,dividend	,notice	,pier	,few	,muggy	,observation	,stand	,borrow	,missile	,teacher	,jest	,bar	,replacement	,fever	,pot	,drain	,slot	,mutual	,decide	,navy	,slide	, asdf	,serious	,loose	,tooth	,undress	,way	,hell	,implicit	,production	,motorcycle	,to	,assembly	,effect	,air	,acute	,age	,compact	,action	,qualification	,accent	,well	,omission	,quest	,flush	,bush	,watch	,cook	,rage	,behead	,ignite	,enemy	,winner	,sell	,tournament	,hostility	,cable	,advance	,scheme	,mirror	,lane	,remedy	,star	,depend	,log	,avant-garde	,doctor	,skilled	,chase	,sock	,history	,deter	,secular	,mouse	,food	,determine	,possibility	,bread	,salad	,peak	,cute	,house	,snub	,loud	,cunning	,corner	,character	,engine	,wonder	,defeat	,tight	,charity	,vigorous	,scenario	,employ	,unlike	,fold	,forbid	,duck	,sweet	,abnormal	,vision	,bed	,sticky	,commission	,ward	,precision	,pursuit	,confession	,leader	,vegetation	,warn	,edge	,clue	,contrast	,meal	,confidence	,block	,company	,rear	,bait	,strategic	,beautiful	,basket	,withdraw	,pan	,tax	,month	,full	,shock	,realize	,good	,belong	,closed	,basic	,temple	,man	,end	,displace	,outside	,afford	,flourish	,pattern	,personal	,tasty	,satisfaction	,voyage	,build	,appearance	,trunk	,crash	,studio	,cold	,item	,population	,banish	,butterfly	,text	,tenant	,vertical	,technique	,neglect	,anger	,ditch	,applied	,duty	,licence	,glimpse	,lobby	,sister	,railcar	,satellite}; // 수요지

수요지의 수요량 => Weight (362개)

Weight = [279 , 422 , 150 , 45 , 142 , 168 , 57 , 90 , 160 , 142 , 78 , 23 , 34 , 0 , 0 , 0 , 129 , 118 , 128 , 64 , 0 , 199 , 236 , 174 , 195 , 103 , 111 , 89 , 24 , 128 , 8 , 0 , 194 , 183 , 196 , 184 , 255 , 205 , 183 , 158 , 311 , 61 , 41 , 68 , 152 , 40 , 72 , 314 , 270 , 196 , 175 , 208 , 200 , 226 , 222 , 361 , 204 , 337 , 153 , 214 , 197 , 198 , 226 , 48 , 267 , 198 , 221 , 228 , 25 , 60 , 67 , 48 , 87 , 85 , 101 , 65 , 67 , 148 , 412 , 154 , 201 , 132 , 251 , 229 , 35 , 246 , 28 , 41 , 26 , 24 , 13 , 15 , 17 , 27 , 11 , 19 , 30 , 27 , 8 , 62 , 259 , 239 , 156 , 26 , 17 , 22 , 16 , 24 , 30 , 23 , 12 , 164 , 264 , 218 , 265 , 123 , 186 , 161 , 280 , 207 , 241 , 88 , 120 , 229 , 294 , 250 , 184 , 166 , 86 , 68 , 84 , 180 , 401 , 353 , 103 , 145 , 220 , 235 , 245 , 244 , 244 , 219 , 119 , 160 , 256 , 187 , 176 , 317 , 231 , 204 , 185 , 176 , 171 , 191 , 254 , 0 , 151 , 100 , 85 , 97 , 342 , 209 , 243 , 240 , 298 , 195 , 199 , 218 , 250 , 230 , 72 , 80 , 26 , 38 , 41 , 45 , 24 , 29 , 30 , 37 , 26 , 29 , 79 , 85 , 92 , 74 , 92 , 78 , 283 , 314 , 67 , 61 , 249 , 124 , 113 , 75 , 71 , 168 , 161 , 148 , 163 , 56 , 84 , 60 , 72 , 87 , 81 , 98 , 129 , 159 , 161 , 208 , 196 , 250 , 104 , 79 , 106 , 80 , 48 , 86 , 214 , 54 , 64 , 81 , 51 , 71 , 45 , 45 , 60 , 22 , 31 , 38 , 141 , 129 , 159 , 92 , 131 , 190 , 95 , 123 , 88 , 36 , 41 , 31 , 27 , 68 , 142 , 123 , 200 , 156 , 152 , 207 , 143 , 151 , 92 , 192 , 123 , 51 , 58 , 54 , 38 , 69 , 111 , 112 , 144 , 78 , 45 , 37 , 49 , 57 , 245 , 81 , 23 , 32 , 92 , 99 , 169 , 298 , 134 , 99 , 100 , 13 , 5 , 11 , 0 , 128 , 150 , 125 , 139 , 153 , 48 , 89 , 16 , 21 , 162 , 202 , 96 , 77 , 31 , 20 , 38 , 29 , 101 , 231 , 124 , 77 , 129 , 78 , 26 , 17 , 45 , 11 , 26 , 22 , 16 , 29 , 55 , 113 , 100 , 29 , 36 , 50 , 55 , 72 , 49 , 44 , 134 , 12 , 5 , 10 , 11 , 0 , 107 , 52 , 100 , 130 , 97 , 73 , 68 , 61 , 11 , 35 , 13 , 13 , 21 , 15 , 7 , 13 , 0 , 7 , 179 , 176 , 188 , 79 , 51 , 46 , 80 , 80 , 74 , 71 , 212 , 303];

입지후보지 (102개)

WellfareCenters = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101}; // 입지 후보지

지역 (15개)

Region={<0,8>, <9,18>, <19,20>, <21,24>, <25,30>, <31,33>, <34,38>, <39,47>, <48,54>, <55,60>, <61,69>, <70,76>, <77,82>, <83,93>, <94,101>};

거리행렬 (102*362 = 36924개)

Distance = [
[~~~, ~~~, ... , ~~~], 
[~~~, ~~~, ... , ~~~], 
...
[~~~, ~~~, ... , ~~~], 
[~~~, ~~~, ... , ~~~]
];

 

반응형

댓글