fslaborg / Graphoscope

A pragmatic approach to network science.
http://fslab.org/Graphoscope/
MIT License
14 stars 6 forks source link

Implement basic operations on core graph representation #6

Closed HarryMcCarney closed 1 year ago

HarryMcCarney commented 1 year ago

Further to this discussion implement agreed syntax for

HarryMcCarney commented 1 year ago

Basic operation are those defined as effecting only one node.

Further to sprint two planning these will be implemented using function overloads for each data structure. There will likely be separate implementations for directed and undirected graphs.

HarryMcCarney commented 1 year ago

In sprint 3 these will be built into the type alias / Adjacency List approach. Probably a combination of Digraph and FGraph.

mikk-c commented 1 year ago

You're probably working on this, but on my tests Measures.Degree.maximum seems to give incorrect results on DiGraph (I'm assuming this function is supposed to be run only on FGraph, or that DiGraph support is coming). I tried the following code:

#r "nuget: Graphoscope"
#r "nuget: FSharpAux.IO"

open Graphoscope
open FSharpAux.IO
open FSharpAux.IO.SchemaReader.Attribute

type MonkeyEdge = {
    [<Field(0)>] Source  : int
    [<Field(1)>] Target  : int
    [<Field(2)>] Groomed : int
}

let monkeyEdges =
    Seq.fromFileWithCsvSchema<MonkeyEdge>("out.moreno_rhesus_rhesus",' ',false,skipLines=2 )

let monkeyDiGraph =
    monkeyEdges
    |> Seq.map (fun mke ->
        mke.Source, sprintf "Monkey_%i" mke.Source,mke.Target,sprintf "Monkey_%i" mke.Target,float mke.Groomed)
    |> DiGraph.ofSeq

let maxDi = Measures.Degree.maximum monkeyDiGraph

printfn "%f" maxDi

This prints "20".

The expected output is difficult to describe, because it is "10" if we want the indegree, or "12" if we want the outdegree, which isn't specified. But it is not 20 in either case (it seems that the code takes the maximum indegree and multiplies by 2).