Safe Haskell | None |
---|
InGraph
Description
Ingress Graph module. The routines in this module support optimizing links between portals in the game Ingress.
- data Vector a = Vec (a, a)
- type Portal = (String, Vector Float)
- type PortalGraph = Gr Portal ()
- emptyGraph :: PortalGraph
- portals :: [([Char], Vector Float)]
- northSaMo :: PortalGraph
- addPortals :: PortalGraph -> [Portal] -> PortalGraph
- newNode :: PortalGraph -> Node
- mean :: Fractional a => [a] -> a
- std :: Fractional a => [a] -> a
- linksCross :: (Portal, Portal) -> (Portal, Portal) -> Bool
- cross2D :: Num a => Vector a -> Vector a -> a
- hamiltonian :: Float -> PortalGraph -> Float
- adjFields :: PortalGraph -> Node -> [(Node, Node)]
- fieldArea :: Portal -> Portal -> Portal -> Float
- fieldAreaG :: PortalGraph -> Node -> Node -> Node -> Float
- portalEnergy :: Float -> PortalGraph -> Node -> Float
- makesCross :: PortalGraph -> (Node, Node) -> Bool
- metropolis :: StdGen -> PortalGraph -> Float -> Int -> PortalGraph
- perturbGraph :: StdGen -> PortalGraph -> (PortalGraph, StdGen)
- stripEdges :: PortalGraph -> PortalGraph
- graphOptimize :: Float -> Int -> PortalGraph -> PortalGraph
- graphStats :: PortalGraph -> (Int, Int, Int)
Documentation
type PortalGraph = Gr Portal ()
addPortals :: PortalGraph -> [Portal] -> PortalGraph
Add a list of portals to a portal graph
newNode :: PortalGraph -> Node
Determine the id of the next node to add
mean :: Fractional a => [a] -> a
std :: Fractional a => [a] -> a
linksCross :: (Portal, Portal) -> (Portal, Portal) -> Bool
Determine whether or not links between two pairs of portals cross
hamiltonian :: Float -> PortalGraph -> Float
Determine the energy of a graph
adjFields :: PortalGraph -> Node -> [(Node, Node)]
Count the number of fields adjacent to a portal. Returns a list of endpoint pairs for each triangle. For instance:
>>>
adjFields g 1
[(2,3),(3,4)]
Specifies that node 1 makes triangles (1,2,3) and (1,3,4).
fieldAreaG :: PortalGraph -> Node -> Node -> Node -> Float
Calculate the area covered by a field, using graph node numbers
portalEnergy :: Float -> PortalGraph -> Node -> Float
Calculate the energy of a single portal. Energy is defined to be the ratio of AP due to destruction over AP due to creation. This is then scaled by the number of fields.
makesCross :: PortalGraph -> (Node, Node) -> Bool
Determine whether a potential link would cross an existing link
metropolis :: StdGen -> PortalGraph -> Float -> Int -> PortalGraph
Implement a simple metropolis algorithm for minimizing the hamiltonian of a portal graph
perturbGraph :: StdGen -> PortalGraph -> (PortalGraph, StdGen)
Create a random modification to a graph. Pick a link to toggle on or off. Continue toggling links until one of the toggles adds a link. This is because the hamiltonian will nearly always judge removal of a link as a higher energy state.
stripEdges :: PortalGraph -> PortalGraph
Remove all of the edges from a graph
graphOptimize :: Float -> Int -> PortalGraph -> PortalGraph
Optimize the links among a collection of nodes.
graphStats :: PortalGraph -> (Int, Int, Int)
Calculate some descriptive numbers summarizing a graph