{-
-- TODO: is this code is still neeed for Display purposes ? -- needs to work with new StateForcing -- does it make sense ?
selectOptimalState ::
  (Ord a,Arith.Sum a,Show (Params.StateForcing a), Show a,RealFloat a) =>
  Params.Optimisation node list sweep vec a ->
  Map Idx.AbsoluteState (Params.StateForcing a) ->
  Type.OptimalSolutionPerState node a ->
  Params.IndexConversionMap ->
  Type.OptimalSolution node a
selectOptimalState _params stateForcing stateMap indexConversionMap =
  let
      g _ Nothing y = y
      g _ x Nothing = x
      g f (Just x) (Just y) = Just (f x y)

  in List.foldl1' (Map.unionWith (g $ ModUt.maxByWithNaN ModUt.fst5))
     $ map (\(st, m) ->
             Map.map (fmap
                      (\(objVal, eta, idx ,env) ->
                        (objVal Arith.~+
                         maybe (error "Base.selectOptimalState")
                         Params.unStateForcing
                         (ModUt.state2absolute st indexConversionMap >>= flip Map.lookup stateForcing),
                         eta, st, idx, env))) m)
     $ Map.toList stateMap
-}

supportPoints ::
  (Ord a,Show (vec a),Vec.Len (vec a),Node.C node,
   Vec.Unique vec [a],
   Vec.Storage vec ([[a]], [Sig.SignalIdx]),
   Vec.Storage vec Sig.SignalIdx,
   Vec.Storage vec Int,
   Vec.Storage vec ([a]),
   Vec.FromList vec,
   Vec.Find vec,
   Vec.Filter vec,
   Vec.Zipper vec,
   Vec.Walker vec,
   Vec.Storage vec a,
   Vec.Singleton vec,
   Arith.Constant a,
   Show a,
   Vec.Storage vec Bool,
   Vec.Lookup vec) =>
  [ TopoIdx.Position node] ->
  Record.PowerRecord node vec a ->
  [(a -> [a])] ->
  Sig.UTDistr vec ([[a]], [Sig.SignalIdx])
supportPoints idList rec functList =
  Sig.getActiveSupportPointsND
  $ zip functList
  $ map (Sig.untype . Record.getSig rec) idList
supportPoints ::
  (Ord a,Show (vec a),Vec.Len (vec a),Node.C node,
   Vec.Unique vec [a],
   Vec.Storage vec ([[a]], [Sig.SignalIdx]),
   Vec.Storage vec Sig.SignalIdx,
   Vec.Storage vec Int,
   Vec.Storage vec ([a]),
   Vec.FromList vec,
   Vec.Find vec,
   Vec.Filter vec,
   Vec.Zipper vec,
   Vec.Walker vec,
   Vec.Storage vec a,
   Vec.Singleton vec,
   Arith.Constant a,
   Show a,
   Vec.Storage vec Bool,
   Vec.Lookup vec) =>
  [ TopoIdx.Position node] ->
  Record.PowerRecord node vec a ->
  [(a -> [a])] ->
  Sig.UTDistr vec ([[a]], [Sig.SignalIdx])
supportPoints idList rec functList =
  Sig.getActiveSupportPointsND
  $ zip functList
  $ map (Sig.untype . Record.getSig rec) idList
supportPoints idList rec functList =
  Sig.getActiveSupportPointsND
  $ zip functList
  $ map (Sig.untype . Record.getSig rec) idList