Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement complement for undirected graphs #237

Merged
merged 6 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Algebra/Graph/Undirected.hs
Original file line number Diff line number Diff line change
Expand Up @@ -701,13 +701,11 @@ toSymmetricRelation = foldg SR.empty SR.vertex SR.overlay SR.connect
{-# INLINE toSymmetricRelation #-}

-- | Complement of a graph.
-- Complexity: /O(m^2+n)/ time, /O(m+n)/ memory where
-- Complexity: /O(m^2)/ time, /O(m^2)/ memory where
--
-- @
-- complement 'empty' == 'empty'
-- complement ('vertex' x) == ('vertex' x)
-- complement ('edge' x y) == ('vertices' [x, y])
-- complement ('star' x [y, z]) == ('overlay' ('vertex' x) ('edge' y z))
snowleopard marked this conversation as resolved.
Show resolved Hide resolved
-- complement . complement == id
-- @
complement :: Ord a => Graph a -> Graph a
Expand Down
10 changes: 2 additions & 8 deletions test/Algebra/Graph/Test/Undirected.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,8 @@ testUndirected = do
test "complement empty == empty" $
complement empty == (empty :: UGI)

test "complement (vertex 1) == (vertex 1)" $
complement (vertex 1) == (vertex 1 :: UGI)

test "complement (edge 1 2) == (vertices [1, 2])" $
complement (edge 1 2) == (vertices [1, 2] :: UGI)

test "complement (star 1 [2, 3]) == (overlay (vertex 1) (edge 2 3))" $
complement (star 1 [2, 3]) == (overlay (vertex 1) (edge 2 3) :: UGI)
test "complement (vertex x) == (vertex x)" $ \(x :: Int) ->
complement (vertex x) == (vertex x :: UGI)

test "complement . complement == id" $ \(x :: UGI) ->
(complement . complement $ x) == x
Expand Down