Attribute constraints matrix is updated by comparing min/max value of old matrix with attribute values of new node
This commit is contained in:
parent
07d2d37bb6
commit
e7c73a33df
@ -170,25 +170,13 @@ constraint :: Attr -> MaxDivergence -> Int -- ^ required number of consistent at
|
|||||||
-> Maybe Constraints
|
-> Maybe Constraints
|
||||||
constraint attr div req (ind, (fulfill, constr), _) newNode =
|
constraint attr div req (ind, (fulfill, constr), _) newNode =
|
||||||
let
|
let
|
||||||
--TODO: UGLY hack... this has to be somewhere .. -.-
|
-- attribute matrix row of node to add
|
||||||
! posInf = read "Infinity" :: Double
|
! attrSlice = A.slice attr (A.Any :. newNode :. A.All)
|
||||||
! negInf = read "-Infinity" :: Double
|
|
||||||
-- convert into Vector of new Indices after appending new node-index
|
|
||||||
! totalInd = A.toUnboxed $ A.computeUnboxedS $ ind ++ A.fromListUnboxed (ix1 1) [newNode]
|
|
||||||
updateConstr :: (DIM2 -> Double) -> DIM2 -> Double
|
updateConstr :: (DIM2 -> Double) -> DIM2 -> Double
|
||||||
updateConstr f sh@(Z:.i:.c) =
|
updateConstr f sh@(Z:.i:.c) =
|
||||||
let
|
|
||||||
! slice = A.slice attr (A.Any :. i)
|
|
||||||
-- TODO: why not compare current bounds with attribute values of new node?
|
|
||||||
! mins = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else posInf)
|
|
||||||
! maxs = A.traverse slice id (\g sh'@(Z :. j)-> if V.any (==j) totalInd then (g sh') else negInf)
|
|
||||||
|
|
||||||
in
|
|
||||||
-- trace (show i P.++ show (A.toList slice) P.++ show c P.++ "\n " P.++ show (A.foldAllS (max) negInf $ maxs)) $
|
|
||||||
case c of
|
case c of
|
||||||
0 -> A.foldAllS (min) posInf mins
|
0 -> min (f sh) (attrSlice!(A.ix1 i))
|
||||||
1 -> A.foldAllS (max) negInf maxs
|
1 -> max (f sh) (attrSlice!(A.ix1 i))
|
||||||
_ -> error "attr wrong"
|
|
||||||
! constrNew = A.computeUnboxedS $ A.traverse constr id updateConstr
|
! constrNew = A.computeUnboxedS $ A.traverse constr id updateConstr
|
||||||
|
|
||||||
--fulfill is borked..
|
--fulfill is borked..
|
||||||
@ -198,7 +186,7 @@ constraint attr div req (ind, (fulfill, constr), _) newNode =
|
|||||||
in if nrHit >= req then Just {-$ trace ("returning const-matrix for "P.++ show (A.toList ind) P.++"\n" P.++ (B.unpack $ outputArray constrNew))-}
|
in if nrHit >= req then Just {-$ trace ("returning const-matrix for "P.++ show (A.toList ind) P.++"\n" P.++ (B.unpack $ outputArray constrNew))-}
|
||||||
(A.computeUnboxedS fulfillNew, constrNew) else Nothing
|
(A.computeUnboxedS fulfillNew, constrNew) else Nothing
|
||||||
|
|
||||||
-- updates the density of a graph extended by a single node
|
-- | Updates the density of a graph extended by a single node
|
||||||
updateDensity :: Adj -- ^ global adjacency matrix of all nodes
|
updateDensity :: Adj -- ^ global adjacency matrix of all nodes
|
||||||
-> Vector A.U Int -- ^ nodes of the base graph
|
-> Vector A.U Int -- ^ nodes of the base graph
|
||||||
-> Int -- ^ node to extend the graph by
|
-> Int -- ^ node to extend the graph by
|
||||||
@ -206,19 +194,7 @@ updateDensity :: Adj -- ^ global adjacency matrix of all nodes
|
|||||||
-> Density -- ^ new density of expanded graph
|
-> Density -- ^ new density of expanded graph
|
||||||
updateDensity adj nodes newNode dens =
|
updateDensity adj nodes newNode dens =
|
||||||
let
|
let
|
||||||
|
|
||||||
|
|
||||||
neighbourSlice = A.map (\n -> fromIntegral $adj!(A.ix2 newNode n)) nodes
|
neighbourSlice = A.map (\n -> fromIntegral $adj!(A.ix2 newNode n)) nodes
|
||||||
{-- awefull asymptotic efficiency
|
|
||||||
A.traverse
|
|
||||||
(A.slice (A.map fromIntegral adj) (A.Any :. newNode)) -- Array
|
|
||||||
id -- same Size
|
|
||||||
(\f sh@(_ :. i) ->
|
|
||||||
if V.any (==i) (A.toUnboxed nodes) then --if connected to graph
|
|
||||||
(f sh) --return connection
|
|
||||||
else
|
|
||||||
0) --never connect to nodes not extisting
|
|
||||||
--}
|
|
||||||
neighbours = A.foldAllS (+) (0::Int) ({- trace (show $ A.computeUnboxedS neighbourSlice)-} neighbourSlice)
|
neighbours = A.foldAllS (+) (0::Int) ({- trace (show $ A.computeUnboxedS neighbourSlice)-} neighbourSlice)
|
||||||
|
|
||||||
{- A.traverse adj (reduceDim) (\f (Z :. i) ->
|
{- A.traverse adj (reduceDim) (\f (Z :. i) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user