anchor.diff:  %%
   %%      We monitor all edge Pids to know when they die or get restarted.
   %%
  -handle_call({add_edges, Src, Dst, Pid, ReadFuns, TransFun, {Dst, WriteFun}}, _From, State) ->
  +handle_call({add_edges, Src, Dst, Pid, ReadFuns, TransFun, WriteFun}, _From, State) ->
  +    {Reply, NewState} = add_edges(Src, Dst, Pid,
  +                                  ReadFuns, TransFun, WriteFun, State),
  +    {reply, Reply, NewState}.
  +
  +%% @private
  +-spec handle_cast(term(), #state{}) -> {noreply, #state{}}.
  +handle_cast(_Request, State) ->
  +    {noreply, State}.
  +
  +%% @private
  +-spec handle_info(term(), #state{}) -> {noreply, #state{}}.
  +
  +%% @doc Remove the edges associated with a lasp process when it terminates.
  +%%
  +%%      Given that lasp processes might get restarted or terminated,
  +%%      we have to know when it happens so we can delete the appropiate
  +%%      edges in the graph.
  +%%
  +handle_info({'DOWN', _, process, Pid, Reason}, #state{dag=Dag,
  +                                                      process_map=PM,
  +                                                      optimized_map=OptMap,
  +                                                      pid_table=PidTable}=State) ->
  +
  +    {ok, Edges} = dict:find(Pid, PM),
  +    NewDag = lists:foldl(fun({F, T}, G) ->
  +        delete_with_pid(G, F, T, Pid)
  +    end, Dag, Edges),
  +
  +    %% If terminated by supervisor, cleave any associated paths.
  +    NewState = case dict:find(Pid, PidTable) of
  +        {ok, Id} -> case Reason of
  +            shutdown ->
  +                cleave_associated_path(Dag, Id, OptMap),
  +                State#state{optimized_map=dict:erase(Id, OptMap),
  +                            pid_table=dict:erase(Pid, PidTable)};
  +
  +            _ ->
  +                State#state{pid_table=dict:erase(Pid, PidTable)}
  +        end;
  +        _ -> State
  +    end,
  +
  +    {noreply, NewState#state{dag=NewDag,
  +                             process_map=dict:erase(Pid, PM)}};
  +
  +handle_info({process_created, Id, Pid, VSeq}, #state{dag=Dag,
  +                                                     optimized_map=OptMap,
  +                                                     pid_table =PidTable}=State) ->
  +    %% @todo Assume the dag didn't change since last call.
  +    %%       Test it once the cleaving has been implemented.
  +    %%
  +    %%       If data races happen even with the cleaving step, we should
  +    %%       perform a check here, before removing the edges.
  +    %%
  +    NewOptMap = remove_edges(Dag, VSeq, Id, Pid, OptMap),
  +    {noreply, State#state{optimized_map=NewOptMap, pid_table=dict:store(Pid, Id, PidTable)}};
  +
  +handle_info(Msg, State) ->
  +    _ = lager:warning("Unhandled messages ~p", [Msg]),
  +    {noreply, State}.
  +
  +%% @private
  +-spec terminate(term(), #state{}) -> term().
  +terminate(_Reason, _State) ->
  +    ok.
  +
  +%% @private
  +-spec code_change(term() | {down, term()}, #state{}, term()) -> {ok, #state{}}.
  +code_change(_OldVsn, State, _Extra) ->
  +    {ok, State}.
  +
  +%%%===================================================================
  +%%% Internal functions
  +%%%===================================================================
  +
  +add_edges(Src, Dst, Pid, ReadFuns, TransFun, {Dst, WriteFun}, State) ->
   
       Dag      = State#state.dag,
       Pm       = State#state.process_map,
  
positive.code:         false ->
              erlang:monitor(process, Pid),
  
              %% For all V in Src, append Pid -> {V, Dst}
              %% in the process map.
              ProcessMap = lists:foldl(fun(El, D) ->
  
negative.code: 
      St = case CtStep of
          ?CONTRACTION_INTERVAL ->
                %% @todo Contraction step
                %%
                %%       How do we prevent a contraction from happening
                %%       as part of the edges created from another contraction?
                %%
                %%       If the dag starts a new contraction step as part of
                %%       another contraction, multiple path contractions may
                %%       happen, leading to multiple edges between vertices.
                %%
                %%       Either make contractions manual, or measure the
                %%       probability of a vertex to be updated if it has been
                %%       changed recently. Paths that contain "active" vertices
                %%       won't be contracted, as they are determined to be changed
                %%       often. Only contract paths that are relatively stable
                %%       (haven't changed in X ticks).
                %%
                %%       Another option is to implement a special function to
                %%       create edges in the graph that don't count towards
                %%       the contraction step count.
                %%
                St0#state{contraction_step=0};
          _ ->
              St0#state{contraction_step = CtStep + 1}
      end,
      {R, St#state{optimized_map = NewOptMap, pid_table = NewPidTable}}.
  
  
  is_graph_error({error, _}) ->
      true;
  