Sha256: b6bf9f5775e5a1750079d9d30dd8be31213e93be3bfa7462c58b53dbe13fd185
Contents?: true
Size: 1.14 KB
Versions: 4
Compression:
Stored size: 1.14 KB
Contents
require 'omf-oml/network' require 'omf-oml/table' include OMF::OML nw = OmlNetwork.new 'mobile_network' nw.node_schema [[:x, :float], [:y, :float], [:capacity, :float]] nw.create_node :n0, :x => 0.2, :y => 0.2, :capacity => 0.3 nw.create_node :n1, :x => 0.8, :y => 0.2, :capacity => 0.5 nw.create_node :n2, :x => 0.8, :y => 0.8, :capacity => 0.8 nw.create_node :n3, :x => 0.2, :y => 0.8, :capacity => 0.8 nw.create_node :m1, :x => 0.5, :y => 0.7, :capacity => 0.8 nw.link_schema [[:load, :float]] l = nw.create_link :l01, :n0, :m1, :load => 0.8 require 'omf_web' OMF::Web.register_datasource nw, :index => :id # Move mobile node Thread.new do begin ts = 0 angle = 0 delta = Math::PI / 6 twoPi = 2 * Math::PI r = 0.25 loop do sleep 1 ts = ts + 1 angle += delta angle -= twoPi if angle >= twoPi nw.transaction do m = nw.node(:m1) #m[:ts] = ts m[:x] = r * Math.sin(angle) + 0.5 m[:y] = r * Math.cos(angle) + 0.5 l[:load] = rand() #puts m.describe end end rescue Exception => ex puts ex puts ex.backtrace.join("\n") end end
Version data entries
4 entries across 4 versions & 1 rubygems