epistemic-group-gossip-0.1.0.0
Copyright(c) Jesper Kuiper 2021
Leander van Boven 2021
Ramon Meffert 2021
LicenseBSD3
Safe HaskellNone
LanguageHaskell2010

GossipGraph

Description

 
Synopsis

Gossip Graph types

type GossipGraph = Gr AgentName Kind Source #

The gossip graph. This is defined in terms of the Graph module.

data Kind Source #

An agent relation label, indicating whether x knows the number of y, or x knows the secret of y.

Constructors

Number 
Secret 

Instances

Instances details
Eq Kind Source # 
Instance details

Defined in GossipGraph

Methods

(==) :: Kind -> Kind -> Bool #

(/=) :: Kind -> Kind -> Bool #

Show Kind Source # 
Instance details

Defined in GossipGraph

Methods

showsPrec :: Int -> Kind -> ShowS #

show :: Kind -> String #

showList :: [Kind] -> ShowS #

type Relation = LEdge Kind Source #

A relation between to agents, either knowledge of number or knowledge of secret.

Pre-made graphs

testGraph :: GossipGraph Source #

Simple graph to be used for testing

testGraph2 :: GossipGraph Source #

Another simple graph with slightly different number relations.

biggerGraph :: GossipGraph Source #

A slightly bigger graph, with five instead of three agents.

defaultGraph :: Int -> GossipGraph Source #

A default graph with generic size. In this graph, every agent only knows their own number.

>>> defaultGraph 3
mkGraph [(0,'a'),(1,'b'),(2,'c')] [(0,0,Number),(0,0,Secret),(1,1,Number),(1,1,Secret),(2,2,Number),(2,2,Secret)]

Graph construction

initialGraph :: Int -> [(Char, [Char])] -> GossipGraph Source #

Generates an initial gossip graph (with no initial shared secrets), based on a list of agents and their known phone numbers. In this initial graph, everyone will only know their own secret.

>>> initialGraph 2 [('a', "ab"), ('b', "b")]
mkGraph [(0,'a'),(1,'b')] [(0,0,Number),(0,0,Secret),(0,1,Number),(1,1,Number),(1,1,Secret)]

Graph inspection

numbersKnownBy :: GossipGraph -> Agent -> [Agent] Source #

Returns the list of agents of which an agent knows the number, given a gossip graph.

secretsKnownBy :: GossipGraph -> Agent -> [Agent] Source #

Returns the list of agents of which an agent knows the secret, given a gossip graph.

hasRelationWith :: GossipGraph -> Agent -> Kind -> Agent -> Bool Source #

Checks whether two agents have some relation, either secret or number.

isGraphComplete :: GossipGraph -> Bool Source #

Check whether each agent is an expert; i.e. knows the secret of everyone.

noAgents :: GossipGraph -> Int Source #

Returns the amount of agents that are present in a gossip graph.

>>> noAgents testGraph
3

Agent-specific functions

idToLab :: Int -> Char Source #

Converts an agent ID to an agent label.

>>> idToLab 0
'a'
>>> idToLab 12
'm'

labToId :: Char -> Int Source #

Converts an agent label to an agent ID.

>>> labToId 'a'
0
>>> labToId 'w'
22

Agent construction

agentFromId :: Int -> Agent Source #

Generates an agent, based on its ID.

>>> agentFromId 0
(0, 'a')
>>> agentFromId 2
(2, 'c')

agentFromLab :: Char -> Agent Source #

Generates an agent, based on its label character.

>>> agentFromLab 'a'
(0, 'a')
>>> agentFromLab 'd'
(3, 'd')

Relation construction

relation :: Agent -> Agent -> Kind -> Relation Source #

Generates a relation between to agents, given a relation kind.

Graph printing

printGraph :: GossipGraph -> IO () Source #

Prints the graph in a readable manner.