-- A single chromosome was used to extend the packing by a number of packages.
combinePlacements (Just (packages, _, chromosomePackages, oqm, used)) (Just (newPackages, newResiduals)) =
  Just (packages ++ newPackages, newResiduals, safeTail chromosomePackages, qm, succ used)
  where
    lengthNew = length newPackages
    qm = if L.null newPackages then oqm
         else M.adjust (\k -> k - lengthNew) (fst $ head newPackages) oqm
    safeTail = modChromsomePackages (drop 1)


-- | Select an element from a list by projecting a selector in [0.0, 1.0]
-- over the indices of the list. Eg. a selector of 1 will always select the last element,
-- 0.5 in the center and 0 at the front.
combinePlacements (Just (packages, _, chromosomePackages, oqm, used)) (Just (newPackages, newResiduals)) =
  Just (packages ++ newPackages, newResiduals, safeTail chromosomePackages, qm, succ used)
  where
    lengthNew = length newPackages
    qm = if L.null newPackages then oqm
         else M.adjust (\k -> k - lengthNew) (fst $ head newPackages) oqm
    safeTail = modChromsomePackages (drop 1)


-- | Select an element from a list by projecting a selector in [0.0, 1.0]
-- over the indices of the list. Eg. a selector of 1 will always select the last element,
-- 0.5 in the center and 0 at the front.
combinePlacements (Just (packages, _, chromosomePackages, oqm, used)) (Just (newPackages, newResiduals)) =
  Just (packages ++ newPackages, newResiduals, safeTail chromosomePackages, qm, succ used)
  where
    lengthNew = length newPackages
    qm = if L.null newPackages then oqm
         else M.adjust (\k -> k - lengthNew) (fst $ head newPackages) oqm
    safeTail = modChromsomePackages (drop 1)


-- | Select an element from a list by projecting a selector in [0.0, 1.0]
-- over the indices of the list. Eg. a selector of 1 will always select the last element,
-- 0.5 in the center and 0 at the front.