Model for my problem (network simulator)

Hello!

I’d like to ask for help for my problem. Maybe the Q isn’t
ruby-specific, but I WILL implement it in ruby, and I want to make a
rubyish program. I hope I can learn from the problem.

So: I had to write a network simulator. It consists of nodes, link
between nodes. The delay of the link should be user-programmable (maybe
proc is the right way, but it must be evaluated in the object’s scope,
because delay is not independent of the link’s state…

And finally the simulator has agents. Agents are programs, which can
migrate. Migration is requested by agent. (Request goes to the node, and
the node does the actual migration…)
Agent must know about their own location, it can ask the node about
outgoing links (so nodes must know about links ending at the node, of
course).

Shall I submit my code? Or did anybody has a model for it already?

thx in advance
Gergo

···


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

“Gergely Kontra” kgergely@mcl.hu schrieb im Newsbeitrag
news:20040503161710.GA16300@mlabdial.hit.bme.hu…

Hello!

I’d like to ask for help for my problem. Maybe the Q isn’t
ruby-specific, but I WILL implement it in ruby, and I want to make a
rubyish program. I hope I can learn from the problem.

So: I had to write a network simulator. It consists of nodes, link
between nodes. The delay of the link should be user-programmable (maybe
proc is the right way, but it must be evaluated in the object’s scope,
because delay is not independent of the link’s state…

And finally the simulator has agents. Agents are programs, which can
migrate. Migration is requested by agent. (Request goes to the node, and
the node does the actual migration…)
Agent must know about their own location, it can ask the node about
outgoing links (so nodes must know about links ending at the node, of
course).

Shall I submit my code? Or did anybody has a model for it already?

What was your question exactly? You seem to have implemented the simulator
already…

As a general OO rule of thumb, take all the interesting nouns and make them
classes. This seems to be pretty much straightforward in your case.

The thing I find more interesting is the scheduling. This could be done
like this (attached).

Regards

robert

schedule.rb (1021 Bytes)

Hey!
I have almost the same code for scheduling. I just used something
similar to this. The only difference: I used relative time, so my method
is called after…
Maybe it worth to make something generally usable?

BTW
Hash.new {|h,k| h[k]= } can be written as
Hash.new {}

···

On 0504, Robert Klemme wrote:

The thing I find more interesting is the scheduling. This could be done
like this (attached).

±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+
http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

Just one little thing (chicken-egg problem): the links should know about
the 2 ending nodes, and nodes must know about in/outgoing links. So how
to easily administrate it?

Gergo

···

On 0504, Robert Klemme wrote:

I’d like to ask for help for my problem. Maybe the Q isn’t
ruby-specific, but I WILL implement it in ruby, and I want to make a
rubyish program. I hope I can learn from the problem.

So: I had to write a network simulator. It consists of nodes, link
between nodes. The delay of the link should be user-programmable (maybe
proc is the right way, but it must be evaluated in the object’s scope,
because delay is not independent of the link’s state…

And finally the simulator has agents. Agents are programs, which can
migrate. Migration is requested by agent. (Request goes to the node, and
the node does the actual migration…)
Agent must know about their own location, it can ask the node about
outgoing links (so nodes must know about links ending at the node, of
course).

Shall I submit my code? Or did anybody has a model for it already?

What was your question exactly? You seem to have implemented the simulator
already…


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

“Gergely Kontra” kgergely@mcl.hu schrieb im Newsbeitrag
news:20040504121319.GA27180@mlabdial.hit.bme.hu…

The thing I find more interesting is the scheduling. This could be
done
like this (attached).
Hey!
I have almost the same code for scheduling. I just used something
similar to this. The only difference: I used relative time, so my method
is called after…

Do you convert to abs time internally or how do you make sure the order is
correct?

Maybe it worth to make something generally usable?

=> RAA

BTW
Hash.new {|h,k| h[k]= } can be written as
Hash.new {}

Nope, that’s not the same:

irb(main):001:0> h=Hash.new {}
=> {}
irb(main):002:0> h[1]
=>
irb(main):003:0> h
=> {}
irb(main):004:0> h=Hash.new {|h,k| h[k]=}
=> {}
irb(main):005:0> h[1]
=>
irb(main):006:0> h
=> {1=>}
irb(main):007:0> RUBY_VERSION
=> “1.8.1”

Your solution makes the idiom “h[key] << something” unusable since all
those arrays never make it into the hash.

robert
···

On 0504, Robert Klemme wrote:

I’d like to ask for help for my problem. Maybe the Q isn’t
ruby-specific, but I WILL implement it in ruby, and I want to make a
rubyish program. I hope I can learn from the problem.

“rubyish program” – does this mean a program in ruby? probably since
you post this here

So: I had to write a network simulator. It consists of nodes, link
between nodes.

Shall I submit my code? Or did anybody has a model for it already?

What was your question exactly? You seem to have implemented the simulator
already…

Just one little thing (chicken-egg problem): the links should know about
the 2 ending nodes, and nodes must know about in/outgoing links. So how
to easily administrate it?

That’s easy in ruby, as ruby is garbage-collected, so it can clean up
circular references by itself. Thus, you can add a list of both the in and
outgoing links to each nodes.

···

On Thu, May 06, 2004 at 10:05:29PM +0900, Gergely Kontra wrote:

On 0504, Robert Klemme wrote:

Oh, yes, I run into the problem, and this is the weird case, where
h[key] << something and h[key] <<= something is different…

Gergo

···

On 0504, Robert Klemme wrote:

Nope, that’s not the same:
irb(main):001:0> h=Hash.new {}
irb(main):002:0> h[1]
irb(main):003:0> h
=> {}
irb(main):004:0> h=Hash.new {|h,k| h[k]=}
irb(main):005:0> h[1]
irb(main):006:0> h
=> {1=>}
Your solution makes the idiom “h[key] << something” unusable since all
those arrays never make it into the hash.


±[ Kontra, Gergelykgergely@mcl.hu PhD student Room IB113 ]---------+

http://www.mcl.hu/~kgergely “Olyan langesz vagyok, hogy |
Mobil:(+36 20) 356 9656 ICQ: 175564914 poroltoval kellene jarnom” |
±- Magyar php mirror es magyar php dokumentacio: http://hu.php.net --+

“Zsban Ambrus” ambrus@math.bme.hu schrieb im Newsbeitrag
news:20040506132651.GB3743@math.bme.hu…

I’d like to ask for help for my problem. Maybe the Q isn’t
ruby-specific, but I WILL implement it in ruby, and I want to make
a
rubyish program. I hope I can learn from the problem.

“rubyish program” – does this mean a program in ruby? probably since
you post this here

So: I had to write a network simulator. It consists of nodes, link
between nodes.

Shall I submit my code? Or did anybody has a model for it already?

What was your question exactly? You seem to have implemented the
simulator
already…

Just one little thing (chicken-egg problem): the links should know
about
the 2 ending nodes, and nodes must know about in/outgoing links. So
how
to easily administrate it?

That’s easy in ruby, as ruby is garbage-collected, so it can clean up
circular references by itself. Thus, you can add a list of both the in
and
outgoing links to each nodes.

IMHO the question was rather how to manage those references so that they
are always in sync. That would be the typical problem with bi directional
references in OO languages. Typically you manually have to write code for
that (unless you find a library that does it gracefully) but if done
properly you need to do it only once and can then reuse that code.

robert
···

On Thu, May 06, 2004 at 10:05:29PM +0900, Gergely Kontra wrote:

On 0504, Robert Klemme wrote:

“Gergely Kontra” kgergely@mcl.hu schrieb im Newsbeitrag
news:20040504125533.GB27180@mlabdial.hit.bme.hu…

···

On 0504, Robert Klemme wrote:

Nope, that’s not the same:
irb(main):001:0> h=Hash.new {}
irb(main):002:0> h[1]
irb(main):003:0> h
=> {}
irb(main):004:0> h=Hash.new {|h,k| h[k]=}
irb(main):005:0> h[1]
irb(main):006:0> h
=> {1=>}
Your solution makes the idiom “h[key] << something” unusable since all
those arrays never make it into the hash.

Oh, yes, I run into the problem, and this is the weird case, where
h[key] << something and h[key] <<= something is different…

Note also that h[key] << something is more efficient since it does only one
hash lookup and no hash update.

Regards

robert

8< snip

Just one little thing (chicken-egg problem): the links should know
about
the 2 ending nodes, and nodes must know about in/outgoing links. So
how
to easily administrate it?

That’s easy in ruby, as ruby is garbage-collected, so it can clean up
circular references by itself. Thus, you can add a list of both the in
and
outgoing links to each nodes.

IMHO the question was rather how to manage those references so that they
are always in sync. That would be the typical problem with bi directional
references in OO languages. Typically you manually have to write code for
that (unless you find a library that does it gracefully) but if done
properly you need to do it only once and can then reuse that code.

robert

Probably (and that is only probably, as in “this is how I have seen
it implemented in other instances by very smart professors”) you’ll
want do do something along the lines of:

  • both the nodes and links have a list of what is attached to them.
  • both are observers and observables
  • a change in the node notifies the link, and vice-versa

Otherwise, if for example only the links initiates the change, then
you can make them be the observables and the nodes just the observers.
Cheers!
-CWS