+{-# LANGUAGE DatatypeContexts #-}
+
module BellmanFord (bellmanFord, BFPath(BFPath)) where
import Data.Graph.Inductive.Graph
import Data.Graph.Inductive.Internal.Queue
-- A naive implementation that is slow for all but the smallest instances
-- (30s on a 20x50 example).
---minCostFlow = NaiveMinCostFlow.minCostFlow,
+minCostFlow = NaiveMinCostFlow.minCostFlow,
-- Uses CS2 (http://www.igsystems.com/cs2/), which requires a license for
-- non-research use but is faster (<1s on a 20x50 example, 64s on a 60x500
-- example). Configure the path to cs2.exe in CS2MinCostFlow.hs. Remember to
-- compile CS2 with -DPRINT_ANS, or this won't work!
-minCostFlow = CS2MinCostFlow.minCostFlow,
+--minCostFlow = CS2MinCostFlow.minCostFlow,
-- The number of reviews each proposal should get.
reviewsEachProposal = 4,
- GHC on your $PATH
- GHC "fgl" package
+(Required packages on Fedora 33 as of 2021-08-12: ghc-{fgl,random}-devel)
+
Compile with "make".
Interactive experimentation
filterRandomized,
indReplicateRandom, indRepeatRandom, indRandomArray
) where
+import Control.Monad
import System.Random
import Data.Array.IArray
import Data.Ix
-- This implementation threads a single RandomGen through the whole process in
-- order to satisfy the monad laws.
+
+-- Migrate according to the guide at
+-- https://gitlab.haskell.org/ghc/ghc/-/wikis/migration/7.10#ghc-says-no-instance-for-applicative-
+-- ~ 2021-08-12
+instance Functor Randomized where
+ fmap = liftM
+
+instance Applicative Randomized where
+ pure x = Randomized (\g -> (x, g))
+ (<*>) = ap
+
instance Monad Randomized where
ma >>= amb = Randomized (\g -> let
Randomized fa = ma
Randomized fb = amb a
in fb g2
)
- return x = Randomized (\g -> (x, g))
-- Splits the generator and runs the argument on the left generator while
-- threading the right generator on. C.f. unsaveInterleaveIO. Use this to
import Control.Concurrent
import Data.Array.IArray
import Data.Graph.Inductive.Graph
-import Data.Graph.Inductive.Graphviz
+-- I couldn't find this module any more. ~ 2021-08-12
+--import Data.Graph.Inductive.Graphviz
import Data.Graph.Inductive.Tree
import Data.List
import System.IO
import System.Random
import System.Posix.IO
import System.Posix.Time
-import System.Process
+-- createPipe creates an ambiguity with System.Posix.IO.createPipe. I think
+-- either should work, so hide this one.
+import System.Process hiding (createPipe)
import PMInstance
import PMConfig
import ProposalMatcher
wH <- fdToHandle wFd
return (rH, wH)
+{- Comment this out because it depends on Data.Graph.Inductive.Graphviz, which I
+ don't have access to at the moment.
+
-- GHCi seems to crash if I call this on a "showInstanceAsGraph" result without
-- having previously forced evaluation of the matching.
goGraph :: (Show a, Show b, Graph gr) => gr a b -> IO ()
-- Then open the file.
goFile fname
+-}
+
-- Both-ways list difference
(/\) :: Eq a => [a] -> [a] -> ([a], [a])
l1 /\ l2 = (l1 \\ l2, l2 \\ l1)
#!/bin/bash
-make && exec ghci -cpp Test "$@"
+make && exec ghci -cpp -fglasgow-exts Test "$@"