swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help on the use of the Graph library


From: Axel von Kamp
Subject: Re: Help on the use of the Graph library
Date: Wed, 31 Mar 1999 10:29:18 +0100

Fabio Mascelloni wrote:

> I've tried to use the Graph library in my simulation, but some tasks
> still remain obscure to me: the graph I've to draw on the canvas in
> represented by a square matrix in which element [i][j]==1 if node i and
> j must be linked toghether ,[i][j]==0
> otherwise.
> In each simulation step ,if [i][j]==1 and a link doesn't already
> exists,it is created.If
> [i][j]==0 and a link is present,it is removed.
> I've implemented the first case in this way
>
> if ( graph[i][j] )
>     if (!([[gnodeList atOffset: i ] linkedTo:[gnodeList atOffset: j ]]
> || [ [gnodeList  atOffset:i] linkedFrom: [ gnodeList atOffset:j ]]))
>                        [agGraph addLinkFrom:[gnodeList atOffset: idx]
> To:[gnodeList atOffset:idx2]];
>
> What I don't have perfectly understood  is how to remove a link between
> two nodes.It seems to me that a predefined method to return a certain
> link doesn't exist.I mean a method of this kind:
>
> - getLinkFrom: abj1 To: obj2
>
> so I'd write
>
> id aLink;
> aLink = getLinkFrom: obj1 To:obj2
> [aLink drop];
>
> What kind of solution do you suggest me ?
> Fabio.

I've been looking around the source code a little. The  "- addLinkFrom:
this To: that " method of DiGraph actually doesn't return the newly
created DiGraphLink. If it did, you could store this link in a separate
matrix and just drop it when you want to delete it. You could use this
approach if you created your links in the following way:

[[gnodeList atOffset: idx]  makeLinkTo: [gnodeList atOffset:idx2]];

because the "- makeLinkTo: aNode" method of DiGraphNode does return the
newly created DiGraphLink.
However, there are methods in DiGraphNode which almost do what you are
looking for:
"- (int)linkedTo: anObj"  and "- (int)linkedFrom: anObj"
Since they do not return the link but only tell you if a link does exist
you could implement modified methods like this:

- getLinkTo: anObj
{
  id index, link;

  index = [toList begin: globalZone];
  while ((link = [index next]))
    if ([link getTo] == anObj)
      {
        [index drop];
        return link;
      }
  [index drop];
  return nil;
}

Then you should be able to remove a link this way:

[[obj1 getLinkTo: obj2] drop];

I hope this helps,
- Axel



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]