ingraph

Safe HaskellNone

InGraph

Contents

Description

Ingress Graph module. The routines in this module support optimizing links between portals in the game Ingress.

Synopsis

Types

data Vector a

Constructors

Vec (a, a) 

Instances

Functor Vector 
Eq a => Eq (Vector a) 
Num a => Num (Vector a)

Allow math to be used with a Vector

Show a => Show (Vector a) 

type Portal = (String, Vector Float)

type PortalGraph = Gr Portal ()

Functions

Graph handling routines

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

stripEdges :: PortalGraph -> PortalGraph

Remove all of the edges from a graph

Mathematical Utilities

mean :: Fractional a => [a] -> a

Arithmetic mean

std :: Fractional a => [a] -> a

Standard deviation

cross2D :: Num a => Vector a -> Vector a -> a

Two dimensional cross product, used for link crossing

Graph queries

linksCross :: (Portal, Portal) -> (Portal, Portal) -> Bool

Determine whether or not links between two pairs of portals cross

adjFields

Arguments

:: PortalGraph

Graph to analyze

-> Node

Find fields with this node as a vertex

-> [(Node, Node)]

A list containing pairs of vertices that make a trianlge with the given reference vertex

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).

fieldArea :: Portal -> Portal -> Portal -> Float

Calculate the area covered by a field

fieldAreaG :: PortalGraph -> Node -> Node -> Node -> Float

Calculate the area covered by a field, using graph node numbers

makesCross :: PortalGraph -> (Node, Node) -> Bool

Determine whether a potential link would cross an existing link

Optimization

hamiltonian :: Float -> PortalGraph -> Float

Determine the energy of a graph

portalEnergy

Arguments

:: Float

Importance of making fields, 0 to 1

-> PortalGraph

The current graph

-> Node

Calculate the energy of this node

-> Float

Returns portal energy

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.

metropolis

Arguments

:: StdGen

Random number generator

-> PortalGraph

Graph to optimize

-> Float

Importance of making fields, 0 to 1

-> Int

Maximum number of iterations

-> PortalGraph

Returns the optimized graph

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.

graphOptimize

Arguments

:: Float

fieldGain: Importance of making fields, from 0 to 1

-> Int

maxIter: Maximum optimzation iterations

-> PortalGraph

portalGraph: Graph to optimize

-> PortalGraph

Returns optimized graph

Optimize the links among a collection of nodes.

Graph measures

countFields :: PortalGraph -> Int

Count the total number of fields created by links in a graph

rankPortals :: PortalGraph -> [Portal]

Rank portals by importance. See rankPortalNodes.

rankPortalNodes :: PortalGraph -> [Node]

Rank portal nodes according to how important they are. Importance is ranked by AP due to destruction.

graphStats

Arguments

:: PortalGraph

The graph to analyze

-> (Int, Int, Int)

Returns enemy AP, friendly AP, and the number of fields as a tuple

Calculate some descriptive numbers summarizing a graph. Return a tuple of (Enemy AP, Friendly AP, Number of Fields)

Misc

portals :: [([Char], Vector Float)]

northSaMo :: PortalGraph

Sample portal graph, for testing