Revision c5c295bc src/Cluster.hs
b/src/Cluster.hs | ||
---|---|---|
46 | 46 |
type Score = Double |
47 | 47 |
|
48 | 48 |
-- | The description of an instance placement. |
49 |
type Placement = (Int, Int, Int) |
|
49 |
type Placement = (Int, Int, Int, Score)
|
|
50 | 50 |
|
51 | 51 |
{- | A cluster solution described as the solution delta and the list |
52 | 52 |
of placements. |
... | ... | |
140 | 140 |
-} |
141 | 141 |
applySolution :: NodeList -> InstanceList -> [Placement] -> NodeList |
142 | 142 |
applySolution nl il sol = |
143 |
let odxes = map (\ (a, b, c) -> (Container.find a il, |
|
144 |
Node.idx (Container.find b nl), |
|
145 |
Node.idx (Container.find c nl)) |
|
143 |
let odxes = map (\ (a, b, c, _) -> (Container.find a il,
|
|
144 |
Node.idx (Container.find b nl),
|
|
145 |
Node.idx (Container.find c nl))
|
|
146 | 146 |
) sol |
147 | 147 |
idxes = (\ (x, _, _) -> x) (unzip3 odxes) |
148 | 148 |
nc = removeInstances nl idxes |
... | ... | |
285 | 285 |
vtail = tail victims |
286 | 286 |
have_tail = (length vtail) > 0 |
287 | 287 |
nodes = Container.elems nl |
288 |
iidx = Instance.idx target |
|
288 | 289 |
in |
289 | 290 |
foldl' |
290 | 291 |
(\ accu_p pri -> |
... | ... | |
309 | 310 |
isNothing new_sec then accu |
310 | 311 |
else let |
311 | 312 |
nx = Container.add sec_idx (fromJust new_sec) pri_nl |
312 |
plc = (Instance.idx target, pri_idx, sec_idx) |
|
313 |
upd_cv = compCV nx |
|
314 |
plc = (iidx, pri_idx, sec_idx, upd_cv) |
|
313 | 315 |
c2 = plc:current |
314 | 316 |
result = |
315 | 317 |
if have_tail then |
... | ... | |
383 | 385 |
upd_nl = fromJust tmp_nl |
384 | 386 |
upd_cvar = compCV upd_nl |
385 | 387 |
upd_il = Container.add tgt_idx new_inst ini_il |
386 |
tmp_plc = filter (\ (t, _, _) -> t /= tgt_idx) ini_plc |
|
387 |
upd_plc = (tgt_idx, pri_idx, sec_idx):tmp_plc |
|
388 |
tmp_plc = filter (\ (t, _, _, _) -> t /= tgt_idx) ini_plc
|
|
389 |
upd_plc = (tgt_idx, pri_idx, sec_idx, upd_cvar):tmp_plc
|
|
388 | 390 |
upd_tbl = Table upd_nl upd_il upd_cvar upd_plc |
389 | 391 |
in |
390 | 392 |
compareTables cur_tbl upd_tbl |
... | ... | |
420 | 422 |
ini_tbl victims |
421 | 423 |
in let |
422 | 424 |
Table _ _ _ best_plc = best_tbl |
423 |
(target, _, _) = head best_plc |
|
425 |
(target, _, _, _) = head best_plc
|
|
424 | 426 |
-- remove the last placed instance from the victims list, it will |
425 | 427 |
-- get another chance the next round |
426 | 428 |
vtail = filter (\inst -> Instance.idx inst /= target) victims |
... | ... | |
543 | 545 |
pmlen = (2*nmlen + 1) |
544 | 546 |
in |
545 | 547 |
unzip $ map |
546 |
(\ (i, p, s) -> |
|
548 |
(\ (i, p, s, c) ->
|
|
547 | 549 |
let inst = Container.find i il |
548 | 550 |
inam = fromJust $ lookup (Instance.idx inst) kti |
549 | 551 |
npri = fromJust $ lookup p ktn |
... | ... | |
554 | 556 |
ostr = (printf "%s:%s" opri osec)::String |
555 | 557 |
nstr = (printf "%s:%s" npri nsec)::String |
556 | 558 |
in |
557 |
(printf " %-*s %-*s => %-*s a=%s" |
|
559 |
(printf " %-*s %-*s => %-*s %.8f a=%s"
|
|
558 | 560 |
imlen inam pmlen ostr |
559 |
pmlen nstr moves, |
|
561 |
pmlen nstr c moves,
|
|
560 | 562 |
cmds) |
561 | 563 |
) sol |
562 | 564 |
|
Also available in: Unified diff