anchor.diff:          if b then Some v 
           else None
   
  +    let getValue k (dict:Dictionary<'K,'V>) =
  +        match (tryGetValue k dict) with 
  +            |Some x -> x
  +            |None -> failwith "Error get"
  +         
  +    let copyRecursive (innerCopyF : 'V -> 'V) (dict:Dictionary<'K,'V>) =
  +        let newDict = Dictionary<'K,'V>()
  +        for kv in dict do
  +            newDict.Add(kv.Key,innerCopyF kv.Value)
  +        newDict
  +
   //----- Louvain ----------
   //                         \
   //----- Graph -> PR FGL ->  -> Louvain auf AA Graph
   //
   
  -type internal ArrayAdjacencyGraph(vertexEdges:Dictionary<'Vertex,LEdge<'Vertex,'Edge>[]>, labels:Dictionary<'Vertex,'Label>) =
  -    
  -    // Number of edges in the graph
  -    let mutable edgeCount = 0
  -
  -    // Dictionary of the lables belonging to the vertices with (k,v) k-> vertex, v-> lable.
  -    let labels :Dictionary<'Vertex,'Label> = labels
  +type ArrayAdjacencyGraph<'Vertex,'Label,'Edge when 'Vertex : equality and 'Edge : equality> internal (vertexEdges:Dictionary<'Vertex,LEdge<'Vertex,'Edge>[]>, labels:Dictionary<'Vertex,'Label>) =
  +    
  +    // Dictionary of the labels belonging to the vertices with (k,v) k-> vertex, v-> label.
  +    let labels : Dictionary<'Vertex,'Label> = labels
       // Dictionary of the edges belonging to the vertices with (k,v) k-> vertex, v-> edges.
       let vertexOutEdges :Dictionary<'Vertex,LEdge<'Vertex,'Edge>[]> = vertexEdges
   
       new () = ArrayAdjacencyGraph(new Dictionary<'Vertex,LEdge<'Vertex,'Edge>[]>(), new Dictionary<'Vertex,'Label>())
           
       new(vertices : LVertex<'Vertex,'Label> list,edges : LEdge<'Vertex,'Edge> list) =
  -        let vertexKeys = vertices |> List.map fst
  +        let vertexArray = vertices  |> Array.ofList
  +        let edgeArray   = edges     |> Array.ofList
  +        
           let vertexEdges = System.Collections.Generic.Dictionary<'Vertex,LEdge<'Vertex,'Edge>[]>()
           let labelDict   = System.Collections.Generic.Dictionary<'Vertex,'Label>()
  -        
  -        for i=0 to vertexKeys.Length-1 do
  -            let vertex  = vertexKeys.[i]
  -            let edges   = List.filter (fun (s, t, w) -> s=vertex ||t=vertex) edges |> Array.ofList          
  +
  +        for i=0 to vertexArray.Length-1 do
  +            let (vertex,label)  = vertexArray.[i]
  +            let edges           = Array.filter (fun (s, t, w) -> s=vertex || t=vertex) edgeArray         
               
  -            labelDict.Add (vertices.[i])                                  
  +            labelDict.Add (vertex,label)                                  
               vertexEdges.Add (vertex,edges)
           
           ArrayAdjacencyGraph(vertexEdges,labelDict)
  -                    
  -    ///Number of edges in the graph
  -    member this.EdgeCount       = edgeCount
  -
  -    ///Returns Some label, if a label for the vertex v exists, else none.
  -    member this.TryGetLabel(v:'Vertex) =        
  -        Dictionary.tryGetValue v labels
  -    
  -    ///Returns the label for the vertex v.
  -    member this.GetLabel(v:'Vertex) = 
  -        match (this.TryGetLabel(v)) with
  -            |Some x     -> x
  -            |None       -> failwith("The vertex v does exist")
  -    
  -    ///Sets the label for the vertex v.
  -    member this.SetLabel((v:'Vertex),(l:'Label)) = 
  -        labels.Item v <- (l)
  -      
  -    ///Lookup the first edge in the graph that matches the conditions, returning a Some value if it exists and None if not.
  -    member this.TryGetEdge((source:'Vertex),(target:'Vertex)) :LEdge<'Vertex,'Edge> option =
  -        let tryGetSource =
  -            Dictionary.tryGetValue source vertexOutEdges
  -
  -        if tryGetSource = None then None
  -        else
  -            let edges = tryGetSource |> Option.get
  -            let rec loop i = 
  -                if i >= edges.Length then None else 
  -                if (edges.[i]|>fun (s,t,w) -> t) = target then Some edges.[i]  else loop (i+1)
  -            loop 0                
  -    
  -    ///Return the first edge in the graph that matches the conditions.
  -    member this.getEdge((source:'Vertex),(target:'Vertex)) :LEdge<'Vertex,'Edge> =
  -        match (this.TryGetEdge(source,target)) with
  -            |Some x -> x
  -            |None   -> failwith "Edge does not exist"
  -
  -    ///Lookup all edges in the graph that matches the conditions, returning a Some value if it exists and None if not.
  -    member this.TryGetEdges((source:'Vertex),(target:'Vertex)) :LEdge<'Vertex,'Edge> list option=
  -        let tryGetSource =
  -            Dictionary.tryGetValue source vertexOutEdges
  -
  -        if tryGetSource = None then None
  -        else
  -            let edges = tryGetSource |> Option.get
  -            
  -            let rec loop i _edges= 
  -                if i >= edges.Length then _edges else 
  -                if (edges.[i] |> fun (s,t,w) -> t) = target then 
  -                    loop (i+1) ((edges.[i])::_edges)  
  -                else 
  -                    loop (i+1) (_edges)
  -            
  -            let _edges = loop 0 []
  -            if  _edges = List.empty then None
  -            else Some _edges              
  -    
  -     ///Return all edges in the graph that matches the conditions
  -    member this.GetEdges((source:'Vertex),(target:'Vertex)) :LEdge<'Vertex,'Edge> [] =
  -        match (this.TryGetEdges(source,target)) with
  -                   |Some x -> (x |> Array.ofList)
  -                   |None   -> [||]
  -
  -    ///Returns true, if the edge is found in the graph, else false.
  -    member this.ContainsEdge(edge:LEdge<'Vertex,'Edge>) :bool =     
  -        
  -        let (source,target,weight) = edge
  -        let edgeOptions = this.TryGetEdges(source,target)
  -        
  -        match edgeOptions with
  -            | Some x -> List.contains(edge) x
  -            | None -> false
  -
  -    ///Returns the degree of the vertex v.
  -    member this.Degree(v:'Vertex) :int =
  -        let mutable edges = Unchecked.defaultof<_> 
  -        if (vertexOutEdges.TryGetValue(v, &edges) && edges <> null) then
  -            edges.Length
  -        else
  -            0
  -    
  -    ///Returns true, if the vertex v does not have edges connected to it. Otherwise, it returns false.
  -    member this.IsOutEdgesEmpty(v:'Vertex) :bool =
  -        this.Degree(v) = 0
  -    
  -    //// Returns all edges connected to the vertex v.
  -    //member this.OutEdges(v : 'Vertex) : LEdge<'Vertex,'Edge> [] =       
  -    //    let tryGetSource =
  -    //        Dictionary.tryGetValue v vertexOutEdges
  -    //        
  -    //    match tryGetSource with
  -    //        | Some x -> x
  -    //        | None -> Array.empty
  -    
  -    ///Lookup all edges connected to the vertex v in the graph, returning a Some value if a binding exists and None if not.
  -    member this.TryGetConnectedEdges((v:'Vertex)) =
  -       (Dictionary.tryGetValue v vertexOutEdges)
  -
  -    ///Lookup all edges connected to the vertex v in the graph, returning an array of connected edges.
  -    member this.GetConnectedEdges((v:'Vertex)) =
  -        match (this.TryGetConnectedEdges(v)) with
  -            |Some x -> x
  -            |None   -> [||]
  -
  -    ///Lookup all edges that target the vertex v in the graph, returning a Some value if a binding exists and None if not.
  -    member this.TryGetInEdges((v:'Vertex)) =
  -        let tryGetSource = (Dictionary.tryGetValue v vertexOutEdges)
  -        
  -        if tryGetSource = None then None
  -        else
  -            let edges = tryGetSource |> Option.get
  -            
  -            let rec loop i _edges= 
  -                if i >= edges.Length then _edges else 
  -                if (edges.[i] |> fun (s,t,w) -> t) = v then 
  -                    loop (i+1) ((edges.[i])::_edges)  
  -                else 
  -                    loop (i+1) (_edges)
  -            
  -            let _edges = loop 0 []
  -            if  _edges = List.empty then None
  -            else Some (_edges |> Array.ofList)
  -    
  -    ///Lookup all edges that target the vertex v in the graph, returning an array of connected edges.
  -    member this.GetInEdges((v:'Vertex)) =
  -        match (this.TryGetInEdges(v)) with
  -            |Some x -> x
  -            |None   -> [||]
  -
  -    ///Lookup all edges that originate from the vertex v in the graph, returning a Some value if a binding exists and None if not.
  -    member this.TryGetOutEdges((v:'Vertex)) =
  -        let tryGetSource = (Dictionary.tryGetValue v vertexOutEdges)
  -        
  -        if tryGetSource = None then None
  -        else
  -            let edges = tryGetSource |> Option.get
  -            
  -            let rec loop i _edges= 
  -                if i >= edges.Length then _edges else 
  -                if (edges.[i] |> fun (s,t,w) -> s) = v then 
  -                    loop (i+1) ((edges.[i])::_edges)  
  -                else 
  -                    loop (i+1) (_edges)
  -            
  -            let _edges = loop 0 []
  -            if  _edges = List.empty then None
  -            else Some (_edges |> Array.ofList)   
  -    
  -    ///Lookup all edges that originate from the vertex v in the graph, returning an array of connected edges.
  -    member this.GetOutEdges((v:'Vertex)) =
  -        match (this.TryGetOutEdges(v)) with
  -            |Some x -> x
  -            |None   -> [||]
  -    
  -    ///Lookup the weight of the edge defined by source and vertex. If it exists, return Some value, else none.
  -    member this.TryGetWeight((source:'Vertex),(target:'Vertex)) =
  -        match (this.TryGetEdge((source),(target))) with
  -            |Some x -> Some(fun (s, t, w) -> w)
  -            |None   -> None
  -    
  -    ///Return the weight of the edge defined by source and vertex
  -    member this.GetWeight((source:'Vertex),(target:'Vertex)) =
  -        match (this.TryGetEdge((source),(target))) with
  -            |Some x -> (fun (s, t, w) -> w)
  -            |None   -> failwith "No weight found"
  -
  -    ///Set the weight of the LEdge defined by source and vertex to be equal weight.
  -    member this.setWeight((source:'Vertex),(target:'Vertex),(weight:'Edge)) =
  -        let edgeListSource = 
  -            match (Dictionary.tryGetValue source vertexOutEdges) with
  -                | Some x    -> x |> Array.map (fun (s, t, w) -> if t=target then (s, t, weight) else (s, t, w))
  -                | None      -> failwith "The source vertex of the edge does not exist in this graph."
  -                 
  -        let edgeListTarget = 
  -            match (Dictionary.tryGetValue target vertexOutEdges) with
  -                | Some x    -> x |> Array.map (fun (s, t, w) -> if s=source then (s, t, weight) else (s, t, w))
  -                | None      -> failwith "The target vertex of the edge does not exist in this graph."
  -        
  -        vertexOutEdges.Item source <- (edgeListSource)
  -        vertexOutEdges.Item target <- (edgeListTarget)
  -        this
  -
  -    ///Returns the number of edges that originate from the vertex v.
  -    member this.InDegree((v:'Vertex)) =
  -        this.TryGetInEdges v
  -        |> Option.map (Array.length)
  -    
  -    ///Returns the number of edges that target the vertex v.
  -    member this.OutDegree((v:'Vertex)) =
  -        this.TryGetOutEdges v
  -        |> Option.map (Array.length)
  -
  -    //member this.OutEdge(v:'Edge, index:int) :LEdge<'Vertex,'Edge>=
  -    //    vertexOutEdges.[v].[index]
  -        
  +       
       ///Returns true, since the graph model is always directed.
       member this.IsDirected :bool =
           true
  
positive.code:     ///Returns true, since parallel edges are allowed
      member this.AllowParallelEdges :bool =
          true
  
      ///Returns true, if the graph contains the vertex, else false.
      member this.ContainsVertex(vertex:'Vertex) :bool =
          vertexOutEdges.ContainsKey(vertex)
  
      ///Returns true, if there are no vertices in the graph, else false.
      member this.IsVerticesEmpty :bool =
          vertexOutEdges.Count = 0
  
      ///Returns the number of vertices of the graph.
      member this.VertexCount :int =
          vertexOutEdges.Count
      
      ///Returns the vertices of the graph.
      member this.Vertices  =
          //for vertices in vertexOutEdges.Keys do
          let result = Array.zeroCreate vertexOutEdges.Count
          let mutable i = 0
          for group in vertexOutEdges do
              result.[i] <- group.Key
              i <- i+1
          result
          
      ///Returns true, if there are no edges in the graph, else false.
      member this.IsEdgesEmpty :bool =
          this.EdgeCount = 0
          
      ///Returns all edges of the graph.
      member this.Edges =
          let result = Array.zeroCreate vertexOutEdges.Count
          let mutable i = 0
          for group in vertexOutEdges do
  
negative.code: ﻿namespace FSharp.FGL.ArrayAdjacencyGraph
  
  open System.Collections.Generic
  open FSharp.FGL //For our Graph method
  
  //  An immutable directed graph data structure efficient for large sparse
  