Sha256: fc598d3908961f8433f618dc396edaeccc357223d22f049d8b04e75f7a13043e

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents




require 'omf_oml/network'
require 'omf_oml/table'

include OMF::OML
  
nw = OmlNetwork.new 'static_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.5, :y => 0.5, :capacity =>  0.8
nw.create_node :n3, :x => 0.8, :y => 0.8, :capacity =>  0.8
nw.create_node :n4, :x => 0.2, :y => 0.8, :capacity =>  0.8

nw.link_schema [[:ts, :float], [:load, :float]]
links = []
links << nw.create_link(:l02, :n0, :n2, :ts => 0, :load => 0.0)
links << nw.create_link(:l12, :n1, :n2, :ts => 0, :load => 0.25)
links << nw.create_link(:l23, :n2, :n3, :ts => 0, :load => 0.5)
links << nw.create_link(:l24, :n2, :n4, :ts => 0, :load => 0.75)

require 'omf_web'
OMF::Web.register_datasource nw.to_table(:nodes, :index => :id)
OMF::Web.register_datasource nw.to_table(:links, :index => :id)

# Create a table which serves the history of an individual link as a slice
#
link_history = nw.to_table(:links)
OMF::Web.register_datasource link_history, :name => 'link_history'

# Change load
Thread.new do
  begin
    ts = 0
    loop do
      sleep 1
      ts = ts + 1
      frac = 1.0 / links.length
      nw.transaction do
        links.each_with_index do |l, i| 
          l[:ts] = ts
          l[:load] = rand() * frac + i * frac 
        end
      end
    end
  rescue Exception => ex
    puts ex
    puts ex.backtrace.join("\n")
  end
end


Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
omf_web-1.2.9 example/demo/data_sources/static_network.rb
omf_web-1.2.8 example/demo/data_sources/static_network.rb
omf_web-1.2.7 example/demo/data_sources/static_network.rb
omf_web-1.2.6 example/demo/data_sources/static_network.rb
omf_web-1.2.5 example/demo/data_sources/static_network.rb
omf_web-1.2.4 example/demo/data_sources/static_network.rb
omf_web-1.2.3 example/demo/data_sources/static_network.rb
omf_web-1.2.2 example/demo/data_sources/static_network.rb
omf_web-1.2.1 example/demo/data_sources/static_network.rb
omf_web-1.2.0 example/demo/data_sources/static_network.rb
omf_web-1.0.0 example/demo/data_sources/static_network.rb
omf_web-0.9.9 example/demo/data_sources/static_network.rb
omf_web-0.9.8 example/demo/data_sources/static_network.rb
omf_web-0.9.7 example/demo/data_sources/static_network.rb