Skip to content

Instantly share code, notes, and snippets.

@liuexp
Created June 17, 2013 10:59
Show Gist options
  • Save liuexp/5796144 to your computer and use it in GitHub Desktop.
Save liuexp/5796144 to your computer and use it in GitHub Desktop.
agt stuff
-- Max VCG by dp (let's forget about memoization for a moment, and that actually 1D dp is enough)
-- usage : [vcg i j [13,11,1] [7,5,3,1] | i<-[0..3], j<-[0..2]]
vcg 0 _ q v = head q * (v!!1)
vcg _ 0 q v = fromIntegral (minBound :: Int)
vcg i j q v |j<i = fromIntegral (minBound :: Int)
|otherwise = max (vcg i (j-1) q v) $ vcg (i-1) (j-1) q v + (q!!j)*(fromIntegral (j+1)*v!!(j+1) - fromIntegral j*(v!!j))
vcgPrice j q v = (q!!j)*(v!!(j+1)) + sum [(v!!(t+1) - v!!t) * q!!t | t<-[j+1..(length q - 1)]]
--vcgUtility j q v =
-- Maximum Envy-free by dp (let's forget about memoization for a moment, and that actually 1D dp is enough)
-- usage :
--
envy 0 _ q v = head q * head v
envy _ 0 q v = fromIntegral (minBound :: Int)
envy i j q v | j<i = fromIntegral (minBound :: Int)
| otherwise = max (envy i (j-1) q v) $ envy (i-1) (j-1) q v + (fromIntegral (i+1)*v!!i - fromIntegral i*v!!(i-1))*q!!j
envyPrice j q v = (q!!j)*(v!!(j+1)) + sum [(v!!(t+1) - v!!t) * q!!t | t<-[j+1..(length q - 1)]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment