Corrected checkConstantEq to actually remove the constant equations, rather than only checking them for consistency
This commit is contained in:
parent
d9b606143e
commit
9d562c0b12
|
@ -216,11 +216,12 @@ mygcdList (x:xs) = foldl mygcd x xs
|
||||||
-- and turns any 2x + y <= 4, 2x + y >= 4 pairs into equalities. The list of such equalities
|
-- and turns any 2x + y <= 4, 2x + y >= 4 pairs into equalities. The list of such equalities
|
||||||
-- (which may well be an empty list) and the remaining inequalities is returned.
|
-- (which may well be an empty list) and the remaining inequalities is returned.
|
||||||
-- As an additional step not specified in the paper, equations with no variables in them are checked
|
-- As an additional step not specified in the paper, equations with no variables in them are checked
|
||||||
-- for consistency. That is, all equations c >= 0 (where c is constant) are checked to ensure c is indeed >= 0.
|
-- for consistency. That is, all equations c >= 0 (where c is constant) are checked to
|
||||||
|
-- ensure c is indeed >= 0, and those equations are removed.
|
||||||
pruneAndCheck :: InequalityProblem -> Maybe (EqualityProblem, InequalityProblem)
|
pruneAndCheck :: InequalityProblem -> Maybe (EqualityProblem, InequalityProblem)
|
||||||
pruneAndCheck ineq = do let (opps,others) = splitEither $ groupOpposites $ map pruneGroup groupedIneq
|
pruneAndCheck ineq = do let (opps,others) = splitEither $ groupOpposites $ map pruneGroup groupedIneq
|
||||||
(opps', eq) <- mapM checkOpposite opps >>* splitEither
|
(opps', eq) <- mapM checkOpposite opps >>* splitEither
|
||||||
checked <- mapM checkConstantEq (concat opps' ++ others)
|
checked <- mapM checkConstantEq (concat opps' ++ others) >>* catMaybes
|
||||||
return (eq, checked)
|
return (eq, checked)
|
||||||
where
|
where
|
||||||
groupedIneq = groupBy (\x y -> EQ == coeffSort x y) $ sortBy coeffSort ineq
|
groupedIneq = groupBy (\x y -> EQ == coeffSort x y) $ sortBy coeffSort ineq
|
||||||
|
@ -283,9 +284,16 @@ pruneAndCheck ineq = do let (opps,others) = splitEither $ groupOpposites $ map p
|
||||||
| (x ! 0) + (y ! 0) == 0 = Just $ Right x
|
| (x ! 0) + (y ! 0) == 0 = Just $ Right x
|
||||||
| otherwise = Just $ Left [x,y]
|
| otherwise = Just $ Left [x,y]
|
||||||
|
|
||||||
checkConstantEq :: InequalityConstraintEquation -> Maybe InequalityConstraintEquation
|
-- The type of this function is quite confusing. We want to use in the Maybe monad, so
|
||||||
checkConstantEq eq | all (== 0) (tail $ elems eq) = if (eq ! 0) >= 0 then Just eq else Nothing
|
-- the outer type indicates error; Nothing is an error. Just x indicates non-failure,
|
||||||
| otherwise = Just eq
|
-- but x may either be Just y (keep the equation) or Nothing (remove it). So the three
|
||||||
|
-- possible returns are:
|
||||||
|
-- * Nothing: Equation inconsistent
|
||||||
|
-- * Just Nothing: Equation redundant
|
||||||
|
-- * Just (Just e) : Keep equation.
|
||||||
|
checkConstantEq :: InequalityConstraintEquation -> Maybe (Maybe InequalityConstraintEquation)
|
||||||
|
checkConstantEq eq | all (== 0) (tail $ elems eq) = if (eq ! 0) >= 0 then Just Nothing else Nothing
|
||||||
|
| otherwise = Just $ Just eq
|
||||||
|
|
||||||
-- | Returns Nothing if there is definitely no solution, or (Just ineq) if
|
-- | Returns Nothing if there is definitely no solution, or (Just ineq) if
|
||||||
-- further investigation is needed
|
-- further investigation is needed
|
||||||
|
|
Loading…
Reference in New Issue
Block a user