time | Calls | line |
---|
| | 2 | clear;
|
| | 3 | profile on
|
| | 4 | %% script ver6
|
| | 5 |
|
| | 6 | %add that student with the same teacher sit in same room
|
| | 7 |
|
| | 8 | %prøve ut med bedre da struktur, ha en liste med studenter som sitter
|
| | 9 | %sammen ikke sjekke alle sammen
|
| | 10 |
|
| | 11 | %prøve ut å bruke categorical arrays for å compare verdier istedenfor
|
| | 12 | %string compare
|
| | 13 |
|
| | 14 | %skrive om optimalisering av kode i rapporten for å korte ned kjøretid
|
| | 15 |
|
| | 16 | %todo
|
| | 17 | %add funk for when students exceed workplace
|
| | 18 | %add funk for when workplace exceed students
|
| | 19 |
|
| | 20 | %vil sitte med studenter med samme behov for arbeidsplass
|
| | 21 |
|
| | 22 | %% read from table
|
| | 23 | %use enumerated data to represent placetype
|
| | 24 |
|
| | 25 | %1 : Har behov for fast arbeidsplass, med PC og skjerm
|
| | 26 | %2 : Har behov for fast arbeidsplass, med skjerm
|
| | 27 | %3 : Har behov for fast arbeidsplass, uten PC-utstyr
|
| | 28 | %4 : Har kun behov for "drop-in"-arbeidsplass
|
| | 29 | %5 : Har ikke behov for arbeidsplass på instituttet
|
| | 30 |
|
| | 31 | %legge til flere kolonner
|
0.388 | 1 | 32 | arbeidsplasser = readtable('AlleArbeidsplasser6deletedsome.xlsx');
|
0.012 | 1 | 33 | temp1 = table('Size',[height(arbeidsplasser) 2],'VariableTypes',{'logical', 'uint8'}, 'VariableNames', {'allocatedtruefalse', 'countroom'});
|
0.030 | 1 | 34 | arbeidsplasser = [arbeidsplasser temp1];
|
| | 35 |
|
0.017 | 1 | 36 | arbeidsplasser.ROM = categorical(arbeidsplasser.ROM);
|
| | 37 |
|
< 0.001 | 1 | 38 | arbeidsplass_categories = categories(arbeidsplasser.ROM);
|
| | 39 |
|
| | 40 | %legge til flere kolonner
|
0.094 | 1 | 41 | soknader = readtable('Soknader6.xlsx', 'ReadRowNames',true);
|
0.004 | 1 | 42 | temp2 = table('Size',[height(soknader) 8],'VariableTypes',{'string', 'string', 'uint8', 'logical', 'logical', 'logical', 'uint8', 'uint8'}, 'VariableNames', {'allocatedroomname','allocatedplacenumber','allocatedplacetype', 'lucky1', 'lucky2', 'lucky3', 'newplacetypetoallocate', 'countoccurence'});
|
0.005 | 1 | 43 | outputtable = [soknader temp2];
|
| | 44 |
|
0.027 | 1 | 45 | outputtable = sortrows(outputtable,1);
|
| | 46 |
|
| | 47 |
|
| | 48 | %convert column faglaerer to categorical datatype for easier comparison
|
| | 49 | %between values later
|
0.001 | 1 | 50 | outputtable.Faglaerer = categorical(outputtable.Faglaerer);
|
< 0.001 | 1 | 51 | Faglaerer_categories = categories(outputtable.Faglaerer);
|
| | 52 |
|
0.013 | 1 | 53 | outputtable.allocatedroomname = categorical(outputtable.allocatedroomname,arbeidsplass_categories);
|
| | 54 |
|
| | 55 | %% Tildele ønsked plasstype for de som har søkt om drop in og ikke behov
|
| | 56 | % siden det ikke er noe begrensninger på tildeling for de type plassene
|
| | 57 |
|
| | 58 | %4 : Har kun behov for "drop-in"-arbeidsplass
|
| | 59 | %5 : Har ikke behov for arbeidsplass på instituttet
|
< 0.001 | 1 | 60 | for index = 1:height(outputtable)
|
0.025 | 180 | 61 | if outputtable{index,1} == 4
|
0.039 | 13 | 62 | outputtable{index,6} = outputtable{index,1};
|
0.018 | 167 | 63 | elseif outputtable{index,1} == 5
|
0.014 | 21 | 64 | outputtable{index,6} = outputtable{index,1};
|
< 0.001 | 180 | 65 | end
|
< 0.001 | 180 | 66 | end
|
| | 67 |
|
| | 68 | %% Compute some numbers to use for control flow
|
| | 69 | %compute number of each type of workplace
|
| | 70 |
|
< 0.001 | 1 | 71 | num_of_workplace1 = 0;
|
< 0.001 | 1 | 72 | num_of_workplace2 = 0;
|
< 0.001 | 1 | 73 | num_of_workplace3 = 0;
|
< 0.001 | 1 | 74 | for index = 1:height(arbeidsplasser)
|
0.015 | 139 | 75 | if arbeidsplasser{index,3} == 1
|
< 0.001 | 92 | 76 | num_of_workplace1 = num_of_workplace1 + 1;
|
0.005 | 47 | 77 | elseif arbeidsplasser{index,3} == 2
|
< 0.001 | 29 | 78 | num_of_workplace2 = num_of_workplace2 + 1;
|
0.002 | 18 | 79 | elseif arbeidsplasser{index,3} == 3
|
< 0.001 | 18 | 80 | num_of_workplace3 = num_of_workplace3 + 1;
|
< 0.001 | 139 | 81 | end
|
< 0.001 | 139 | 82 | end
|
| | 83 |
|
| | 84 | %find number of students that want each type
|
< 0.001 | 1 | 85 | studentwantsworkplace1 = 0;
|
< 0.001 | 1 | 86 | studentwantsworkplace2 = 0;
|
< 0.001 | 1 | 87 | studentwantsworkplace3 = 0;
|
< 0.001 | 1 | 88 | for index = 1:height(outputtable)
|
0.019 | 180 | 89 | if outputtable{index,1} == 1
|
< 0.001 | 95 | 90 | studentwantsworkplace1 = studentwantsworkplace1 + 1;
|
0.009 | 85 | 91 | elseif outputtable{index,1} == 2
|
< 0.001 | 31 | 92 | studentwantsworkplace2 = studentwantsworkplace2 + 1;
|
0.006 | 54 | 93 | elseif outputtable{index,1} == 3
|
< 0.001 | 20 | 94 | studentwantsworkplace3 = studentwantsworkplace3 + 1;
|
< 0.001 | 180 | 95 | end
|
< 0.001 | 180 | 96 | end
|
| | 97 |
|
| | 98 |
|
| | 99 | %% choose lucky people to optimize
|
| | 100 |
|
| | 101 | %preallocate some values that some of will get written over later
|
< 0.001 | 1 | 102 | for i = 1:height(outputtable)
|
0.117 | 180 | 103 | outputtable{i, 10} = outputtable{i, 1};
|
< 0.001 | 180 | 104 | end
|
| | 105 |
|
| | 106 | %skrive om hvordan man velger riktig i rapporten
|
| | 107 | %må velge unike verdier bare 1 gang når man velger "lucky" folk
|
| | 108 | %https://se.mathworks.com/matlabcentral/answers/296686-randomly-select-different-elements-of-a-vector
|
| | 109 |
|
| | 110 |
|
| | 111 |
|
| | 112 | %indices for those with origbehovforarbeidsplass == 1
|
0.003 | 1 | 113 | index_orig_1 = find(outputtable{:,1}==1);
|
| | 114 |
|
| | 115 | %TODO: add option to increase prob of those lucky
|
| | 116 |
|
| | 117 |
|
| | 118 | %select who to be lucky
|
< 0.001 | 1 | 119 | for i = 1:num_of_workplace1
|
< 0.001 | 92 | 120 | ind = randperm(numel(index_orig_1), 1); % select one element out of numel(x) elements, with the probability of occurrence of the element in x
|
< 0.001 | 92 | 121 | luckypeople_1(i) = index_orig_1(ind);
|
< 0.001 | 92 | 122 | index_orig_1(index_orig_1==luckypeople_1(i)) = []; % delete this element from the sample, such that the picked elements are unique
|
< 0.001 | 92 | 123 | end
|
| | 124 |
|
| | 125 |
|
| | 126 | %insert values into table for later functions to use
|
< 0.001 | 1 | 127 | for index = luckypeople_1
|
0.052 | 92 | 128 | outputtable{index, 7} = 1;
|
< 0.001 | 92 | 129 | end
|
| | 130 |
|
| | 131 | %insert values into table for later functions to use
|
< 0.001 | 1 | 132 | for index = 1:height(outputtable)
|
0.031 | 180 | 133 | if outputtable{index, 10} == 1 && outputtable{index, 7} ~= 1
|
0.002 | 3 | 134 | outputtable{index, 10} = 2;
|
< 0.001 | 180 | 135 | end
|
< 0.001 | 180 | 136 | end
|
| | 137 |
|
| | 138 | %% now for workplace_2
|
| | 139 |
|
| | 140 | %indices for those with origbehovforarbeidsplass == 2
|
0.001 | 1 | 141 | index_orig_2 = find(outputtable{:,10}==2);
|
| | 142 |
|
| | 143 | % add duplicates to increase prob of those who should have higher prob
|
| | 144 | %do this multiple times
|
< 0.001 | 1 | 145 | temparray2 = find(outputtable{:,10}==2 & outputtable{:,1}==2);
|
| | 146 |
|
| | 147 | %select how many times
|
< 0.001 | 1 | 148 | increaseprob1 = 2;
|
< 0.001 | 1 | 149 | for i = 1:increaseprob1
|
< 0.001 | 2 | 150 | index_orig_2 = cat(1,index_orig_2,temparray2);
|
< 0.001 | 2 | 151 | end
|
| | 152 |
|
| | 153 | %select who to be lucky
|
< 0.001 | 1 | 154 | for i = 1:num_of_workplace2
|
< 0.001 | 29 | 155 | ind = randperm(numel(index_orig_2), 1); % select one element out of numel(x) elements, with the probability of occurrence of the element in x
|
< 0.001 | 29 | 156 | luckypeople_2(i) = index_orig_2(ind);
|
< 0.001 | 29 | 157 | index_orig_2(index_orig_2==luckypeople_2(i)) = []; % delete this element from the sample, such that the picked elements are unique
|
< 0.001 | 29 | 158 | end
|
| | 159 |
|
| | 160 | %insert values into table for later functions to use
|
< 0.001 | 1 | 161 | for index = luckypeople_2
|
0.016 | 29 | 162 | outputtable{index, 8} = 1;
|
< 0.001 | 29 | 163 | end
|
| | 164 |
|
| | 165 | %insert values into table for later functions to use
|
< 0.001 | 1 | 166 | for index = 1:height(outputtable)
|
0.023 | 180 | 167 | if outputtable{index, 10} == 2 && outputtable{index, 8} ~= 1
|
0.003 | 5 | 168 | outputtable{index, 10} = 3;
|
< 0.001 | 180 | 169 | end
|
< 0.001 | 180 | 170 | end
|
| | 171 |
|
| | 172 | %% now for workplace_3
|
| | 173 | %indices for those with origbehovforarbeidsplass == 3
|
< 0.001 | 1 | 174 | index_orig_3 = find(outputtable{:,10}==3);
|
| | 175 |
|
| | 176 |
|
| | 177 | % add duplicates to increase prob of those who should have higher prob
|
| | 178 | %do this multiple times
|
< 0.001 | 1 | 179 | temparray3 = find(outputtable{:,10}==3 & outputtable{:,1}==3);
|
| | 180 |
|
| | 181 | %select how many times
|
< 0.001 | 1 | 182 | increaseprob2 = 2;
|
< 0.001 | 1 | 183 | for i = 1:increaseprob2
|
< 0.001 | 2 | 184 | index_orig_3 = cat(1,index_orig_3,temparray3);
|
< 0.001 | 2 | 185 | end
|
| | 186 |
|
| | 187 | %select who to be lucky
|
< 0.001 | 1 | 188 | for i = 1:num_of_workplace3
|
< 0.001 | 18 | 189 | ind = randperm(numel(index_orig_3), 1); % select one element out of numel(x) elements, with the probability of occurrence of the element in x
|
< 0.001 | 18 | 190 | luckypeople_3(i) = index_orig_3(ind);
|
< 0.001 | 18 | 191 | index_orig_3(index_orig_3==luckypeople_3(i)) = []; % delete this element from the sample, such that the picked elements are unique
|
< 0.001 | 18 | 192 | end
|
| | 193 |
|
| | 194 | %insert values into table for later functions to use
|
< 0.001 | 1 | 195 | for index = luckypeople_3
|
0.010 | 18 | 196 | outputtable{index, 9} = 1;
|
< 0.001 | 18 | 197 | end
|
| | 198 |
|
| | 199 | %insert values into table for later functions to use
|
< 0.001 | 1 | 200 | for index = 1:height(outputtable)
|
0.022 | 180 | 201 | if outputtable{index, 10} == 3 && outputtable{index, 9} ~= 1
|
0.004 | 7 | 202 | outputtable{index, 10} = 4;
|
< 0.001 | 180 | 203 | end
|
< 0.001 | 180 | 204 | end
|
| | 205 |
|
| | 206 | %% compute room with most places and veilere with most students
|
| | 207 | %% add numbers to extra columns in table
|
< 0.001 | 1 | 208 | exp11 = (arbeidsplasser.TypeArbeidsplass == 1);
|
0.003 | 1 | 209 | arbeidsplasser1 = arbeidsplasser.ROM(exp11,:);
|
< 0.001 | 1 | 210 | categories(arbeidsplasser1);
|
< 0.001 | 1 | 211 | count_arbeidsplass1 = countcats(arbeidsplasser1);
|
0.016 | 1 | 212 | testtable11 = table(count_arbeidsplass1);
|
0.004 | 1 | 213 | testtable11.Properties.RowNames = arbeidsplass_categories;
|
| | 214 |
|
< 0.001 | 1 | 215 | exp12 = (outputtable.BehovForArbeidsplass == 1);
|
< 0.001 | 1 | 216 | outputtableFaglaerer1 = outputtable.Faglaerer(exp12,:);
|
< 0.001 | 1 | 217 | categories(outputtableFaglaerer1);
|
< 0.001 | 1 | 218 | count_Faglaerer1 = countcats(outputtableFaglaerer1);
|
< 0.001 | 1 | 219 | testtable12 = table(count_Faglaerer1);
|
< 0.001 | 1 | 220 | testtable12.Properties.RowNames = Faglaerer_categories;
|
| | 221 |
|
< 0.001 | 1 | 222 | exp21 = (arbeidsplasser.TypeArbeidsplass == 2);
|
< 0.001 | 1 | 223 | arbeidsplasser2 = arbeidsplasser.ROM(exp21,:);
|
< 0.001 | 1 | 224 | categories(arbeidsplasser2);
|
< 0.001 | 1 | 225 | count_arbeidsplass2 = countcats(arbeidsplasser2);
|
< 0.001 | 1 | 226 | testtable21 = table(count_arbeidsplass2);
|
< 0.001 | 1 | 227 | testtable21.Properties.RowNames = arbeidsplass_categories;
|
| | 228 |
|
< 0.001 | 1 | 229 | exp22 = (outputtable.BehovForArbeidsplass == 2);
|
< 0.001 | 1 | 230 | outputtableFaglaerer2 = outputtable.Faglaerer(exp22,:);
|
< 0.001 | 1 | 231 | categories(outputtableFaglaerer2);
|
< 0.001 | 1 | 232 | count_Faglaerer2 = countcats(outputtableFaglaerer2);
|
< 0.001 | 1 | 233 | testtable22 = table(count_Faglaerer2);
|
< 0.001 | 1 | 234 | testtable22.Properties.RowNames = Faglaerer_categories;
|
| | 235 |
|
< 0.001 | 1 | 236 | exp31 = (arbeidsplasser.TypeArbeidsplass == 1);
|
< 0.001 | 1 | 237 | arbeidsplasser3 = arbeidsplasser.ROM(exp31,:);
|
< 0.001 | 1 | 238 | categories(arbeidsplasser3);
|
< 0.001 | 1 | 239 | count_arbeidsplass3 = countcats(arbeidsplasser3);
|
< 0.001 | 1 | 240 | testtable31 = table(count_arbeidsplass3);
|
< 0.001 | 1 | 241 | testtable31.Properties.RowNames = arbeidsplass_categories;
|
| | 242 |
|
< 0.001 | 1 | 243 | exp32 = (outputtable.BehovForArbeidsplass == 1);
|
< 0.001 | 1 | 244 | outputtableFaglaerer3 = outputtable.Faglaerer(exp32,:);
|
< 0.001 | 1 | 245 | categories(outputtableFaglaerer3);
|
< 0.001 | 1 | 246 | count_Faglaerer3 = countcats(outputtableFaglaerer3);
|
< 0.001 | 1 | 247 | testtable32 = table(count_Faglaerer3);
|
< 0.001 | 1 | 248 | testtable32.Properties.RowNames = Faglaerer_categories;
|
| | 249 |
|
| | 250 | % add to arbeidsplasser
|
< 0.001 | 1 | 251 | for index = 1:height(arbeidsplasser)
|
0.015 | 139 | 252 | switch arbeidsplasser{index,3}
|
< 0.001 | 139 | 253 | case 1
|
0.085 | 92 | 254 | arbeidsplasser{index,5} = testtable11{cellstr(arbeidsplasser{index,1}), 1};
|
< 0.001 | 47 | 255 | case 2
|
0.025 | 29 | 256 | arbeidsplasser{index,5} = testtable21{cellstr(arbeidsplasser{index,1}), 1};
|
< 0.001 | 18 | 257 | case 3
|
0.016 | 18 | 258 | arbeidsplasser{index,5} = testtable31{cellstr(arbeidsplasser{index,1}), 1};
|
< 0.001 | 139 | 259 | end
|
< 0.001 | 139 | 260 | end
|
| | 261 |
|
| | 262 | %add to outputtable
|
< 0.001 | 1 | 263 | for index = 1:height(outputtable)
|
0.019 | 180 | 264 | switch outputtable{index,10}
|
< 0.001 | 180 | 265 | case 1
|
0.078 | 92 | 266 | outputtable{index,11} = testtable12{cellstr(outputtable{index,3}), 1};
|
< 0.001 | 88 | 267 | case 2
|
0.025 | 29 | 268 | outputtable{index,11} = testtable22{cellstr(outputtable{index,3}), 1};
|
< 0.001 | 59 | 269 | case 3
|
0.016 | 18 | 270 | outputtable{index,11} = testtable32{cellstr(outputtable{index,3}), 1};
|
< 0.001 | 180 | 271 | end
|
< 0.001 | 180 | 272 | end
|
| | 273 |
|
| | 274 | %% try to sort based on number of occurenses of room size and faglaerer
|
| | 275 |
|
0.015 | 1 | 276 | arbeidsplasser = sortrows(arbeidsplasser,[3 5],{'ascend' 'descend'});
|
| | 277 |
|
0.001 | 1 | 278 | outputtable = sortrows(outputtable,[10 11],{'ascend' 'descend'});
|
| | 279 |
|
| | 280 |
|
| | 281 |
|
| | 282 | %% dumb preassign workplaces
|
| | 283 | %this needs to change to use lucky people
|
| | 284 | % assign workplace 1
|
| | 285 |
|
< 0.001 | 1 | 286 | for index = 1:height(outputtable)
|
0.019 | 180 | 287 | if outputtable{index, 10} == 1
|
< 0.001 | 92 | 288 | for index2 = 1:height(arbeidsplasser)
|
1.237 | 12788 | 289 | if arbeidsplasser{index2, 3} == 1
|
1.235 | 8464 | 290 | if (outputtable{index,6} == 0) && (arbeidsplasser{index2, 4} == 0)
|
0.062 | 92 | 291 | outputtable(index,4:6) = arbeidsplasser(index2, 1:3);
|
0.062 | 92 | 292 | arbeidsplasser{index2, 4} = 1;
|
< 0.001 | 8464 | 293 | end
|
< 0.001 | 12788 | 294 | end
|
0.001 | 12788 | 295 | end
|
< 0.001 | 180 | 296 | end
|
< 0.001 | 180 | 297 | end
|
| | 298 |
|
| | 299 | % assign workplace 2
|
| | 300 |
|
< 0.001 | 1 | 301 | for index = 1:height(outputtable)
|
0.018 | 180 | 302 | if outputtable{index, 10} == 2
|
< 0.001 | 29 | 303 | for index2 = 1:height(arbeidsplasser)
|
0.394 | 4031 | 304 | if arbeidsplasser{index2, 3} == 2
|
0.127 | 841 | 305 | if (outputtable{index,6} == 0) && (arbeidsplasser{index2, 4} == 0)
|
0.017 | 29 | 306 | outputtable(index,4:6) = arbeidsplasser(index2, 1:3);
|
0.020 | 29 | 307 | arbeidsplasser{index2, 4} = 1;
|
< 0.001 | 841 | 308 | end
|
< 0.001 | 4031 | 309 | end
|
< 0.001 | 4031 | 310 | end
|
< 0.001 | 180 | 311 | end
|
< 0.001 | 180 | 312 | end
|
| | 313 |
|
| | 314 | % assign workplace 3
|
| | 315 |
|
< 0.001 | 1 | 316 | for index = 1:height(outputtable)
|
0.018 | 180 | 317 | if outputtable{index, 10} == 3
|
< 0.001 | 18 | 318 | for index2 = 1:height(arbeidsplasser)
|
0.245 | 2502 | 319 | if arbeidsplasser{index2, 3} == 3
|
0.050 | 324 | 320 | if (outputtable{index,6} == 0) && (arbeidsplasser{index2, 4} == 0)
|
0.011 | 18 | 321 | outputtable(index,4:6) = arbeidsplasser(index2, 1:3);
|
0.012 | 18 | 322 | arbeidsplasser{index2, 4} = 1;
|
< 0.001 | 324 | 323 | end
|
< 0.001 | 2502 | 324 | end
|
< 0.001 | 2502 | 325 | end
|
< 0.001 | 180 | 326 | end
|
< 0.001 | 180 | 327 | end
|
| | 328 |
|
| | 329 |
|
| | 330 | %% inner optimize
|
| | 331 |
|
< 0.001 | 1 | 332 | tic
|
0.218 | 1 | 333 | computecost(outputtable)
|
< 0.001 | 1 | 334 | toc
|
< 0.001 | 1 | 335 | Sol_Best = outputtable;
|
| | 336 |
|
< 0.001 | 1 | 337 | Candidate_best = outputtable; % zeros(size(Sol_0));
|
| | 338 |
|
< 0.001 | 1 | 339 | iterations = 1;
|
| | 340 |
|
| | 341 | %plotting data
|
| | 342 | % cost_vector = computecost(Candidate_best);
|
| | 343 | %
|
| | 344 | % [constraint1(2), constraint2(2), constraint3(2)] = computenumber(Candidate_best);
|
| | 345 |
|
| | 346 |
|
| | 347 | %while ~(stoppingCondition()) %maybe something like Sol_Best == Candidate_best;
|
| | 348 | % temp1 = getrowcost(outputtable);
|
| | 349 | % rowstooptimize = find(temp1);
|
| | 350 |
|
< 0.001 | 1 | 351 | loopssinceimprovement = 0;
|
| | 352 |
|
< 0.001 | 1 | 353 | while loopssinceimprovement < 2 && iterations < 10
|
< 0.001 | 2 | 354 | mostcostindex = 1;
|
0.373 | 2 | 355 | values = getrowmostcost(Sol_Best);
|
0.381 | 2 | 356 | temp1 = getrowcost(outputtable);
|
< 0.001 | 2 | 357 | [temp1sorted , sortindex] = sort(temp1, 'descend');
|
< 0.001 | 2 | 358 | rowstooptimize = find(temp1);
|
| | 359 |
|
| | 360 | % temp3 = getrowcost(outputtable);
|
| | 361 | %
|
| | 362 | % if temp3 == 0
|
| | 363 | % continue
|
| | 364 | % end
|
| | 365 |
|
| | 366 |
|
< 0.001 | 2 | 367 | loopssinceimprovement = 0;
|
| | 368 |
|
| | 369 | %while ((loopssinceimprovement <= 2)) %maybe something like Sol_Best == Candidate_best;
|
| | 370 |
|
0.227 | 2 | 371 | Sol_neighbors = getneighborsof(Sol_Best,sortindex(mostcostindex)); % list of neighbors % find best way to get neighbors
|
| | 372 |
|
< 0.001 | 2 | 373 | for i = 1:size(Sol_neighbors, 2)
|
32.410 | 184 | 374 | tempvalue1 = computecost(Candidate_best);
|
32.443 | 184 | 375 | if computecost(Sol_neighbors{i}) < tempvalue1
|
< 0.001 | 2 | 376 | Candidate_best = Sol_neighbors{i};
|
0.352 | 2 | 377 | tempvalue1 = computecost(Candidate_best);
|
< 0.001 | 184 | 378 | end
|
| | 379 |
|
< 0.001 | 184 | 380 | end
|
0.695 | 2 | 381 | if computecost(Candidate_best) < computecost(Sol_Best)
|
< 0.001 | 1 | 382 | Sol_Best = Candidate_best;
|
< 0.001 | 1 | 383 | loopssinceimprovement = 0;
|
< 0.001 | 1 | 384 | disp('new Sol_Best');
|
< 0.001 | 1 | 385 | mostcostindex = 1;
|
< 0.001 | 1 | 386 | else
|
< 0.001 | 1 | 387 | loopssinceimprovement = loopssinceimprovement + 1;
|
< 0.001 | 1 | 388 | disp('no new Sol_Best');
|
< 0.001 | 1 | 389 | mostcostindex = mostcostindex + 1;
|
< 0.001 | 1 | 390 | loopssinceimprovement = loopssinceimprovement + 1;
|
< 0.001 | 2 | 391 | end
|
| | 392 | %
|
| | 393 | % cost_vector(iterations) = computecost(Sol_Best);
|
| | 394 | %
|
| | 395 | % [constraint1(iterations), constraint2(iterations), constraint3(iterations)] = computenumber(Sol_Best);
|
< 0.001 | 2 | 396 | iterations = iterations + 1;
|
| | 397 | %end
|
| | 398 |
|
| | 399 |
|
< 0.001 | 2 | 400 | disp('new outer loop');
|
< 0.001 | 2 | 401 | disp(iterations);
|
< 0.001 | 2 | 402 | end
|
| | 403 |
|
| | 404 | %%getneighborsof(). finne swaps med andre studenter som har samme emne, og
|
| | 405 | %%i tillegg returnere en subset av neighboors med studenter som bidrar til
|
| | 406 | %%objectfunksjonen
|
| | 407 |
|
| | 408 |
|
| | 409 | %%
|
| | 410 |
|
| | 411 | %TODO:assign those who didnt get any designated places to drop in palces
|
| | 412 |
|
0.184 | 1 | 413 | [outputcost1before, outputcost2before, outputcost3before] = computenumber(outputtable);
|
| | 414 |
|
0.181 | 1 | 415 | [outputcost1after, outputcost2after, outputcost3after] = computenumber(Sol_Best);
|
| | 416 |
|
0.179 | 1 | 417 | fprintf('cost of before table: %d \n', computecost(outputtable));
|
< 0.001 | 1 | 418 | fprintf('Before: cost1: %d ;cost2: %d ;cost3: %d ; \n', outputcost1before, outputcost2before, outputcost3before);
|
| | 419 |
|
0.178 | 1 | 420 | fprintf('cost of after table: %d \n', computecost(Sol_Best));
|
< 0.001 | 1 | 421 | fprintf('After: cost1: %d ;cost2: %d ;cost3: %d ; \n', outputcost1after, outputcost2after, outputcost3after);
|
| | 422 |
|
0.178 | 1 | 423 | fprintf('row with most cost in before table: %d \n', getrowmostcost(outputtable));
|
| | 424 |
|
0.180 | 1 | 425 | fprintf('row with most cost in after table: %d \n', getrowmostcost(Sol_Best));
|
| | 426 |
|
< 0.001 | 1 | 427 | fprintf('Finished \n')
|
| | 428 |
|
0.003 | 1 | 429 | profile viewer
|
| | 430 | profsave
|
Other subfunctions in this file are not included in this listing.