Commit 08931e0a authored by Tim Molderez's avatar Tim Molderez

Migrating load balancing example to its own repo

parent 582157df
......@@ -19,12 +19,7 @@
use Mix.Config
config :marlon,
connect_handler: {:example, :connect_node},
disconnect_handler: {:example, :disconnect_node},
python_path: 'python',
communication_time: 2000,
processing_time: 5000,
visualization: true
config :libcluster,
topologies: [
......@@ -38,12 +33,5 @@ config :libcluster,
]
]
config :smile_it_demo_ui, SmileItDemoUiWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "/bytVRunQxwRMpbJ15th2HpDDHJchOMwl+SvoIjLMgnjcxtL9wdT8S3aoIsAneFa",
render_errors: [view: SmileItDemoUiWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: SmileItDemoUi.PubSub,
adapter: Phoenix.PubSub.PG2]
config :logger,
level: :info
\ No newline at end of file
# To run this example: iex -S mix run -r lib/examples/thermostat/thermostat-multi.exs
use Marlon
defactor House do
def init([init_temp]) do
{:ok, hp} = Heatpump.start_link([init_temp], [])
agent = Heatpump.attach_agent(hp, DistributeLoad)
{:ok, %{heatpump: hp, iterations: 1000}}
end
async def loop(this) do
Heatpump.step(this.heatpump)
Process.send_after self(), {:loop_reply}, 50
{:noreply, this}
end
reply def loop_reply(this) do
if (this.iterations > 0) do
House.loop(self())
end
{:noreply, %{this | iterations: this.iterations - 1}}
end
end
defactor Heatpump do
def init([init_temp]) do
{:ok, %{temperature: init_temp, load: 0}}
end
async def step(this) do
IO.puts (Kernel.inspect(self()) <> " temperature: " <> Float.to_string(this.temperature))
Heatpump.do_action(self()) # The attached agent should now do an action
{:noreply, this}
end
async def on(this) do
...
Heatpump.update_reward(self(), hp)
{:noreply, hp}
end
async def off(this) do
...
Heatpump.update_reward(self(), hp)
{:noreply, hp}
end
end
defgoal DistributeLoad do
type Marlon.ESRL
params [discount_factor: 0.0, learning_rate: 1.0, epsilon: 0.8]
actions [on: [], off: []]
shared [:load]
shared_deviation [load: 0.5]
reward fn(_agent, hp, shared) ->
1 / Util.sum(shared.load))
end
end
{:ok, house_1} = House.start_link([5.0], [])
{:ok, house_2} = House.start_link([8.0], [])
House.loop(house_1)
House.loop(house_2)
\ No newline at end of file
......@@ -74,8 +74,7 @@ defactor LoadBalancingExample do
if (this[:master] != nil) do
Master.work_cancelled(this[:master], node)
if (Application.fetch_env!(:marlon, :visualization)) do
ip = Enum.at(String.split(Atom.to_string(node), "@"),1)
Marlon.Utils.visualize(:broker_node, {:leave, ip})
Marlon.Utils.visualize(:broker_node, {:leave, node})
end
end
{:noreply, this}
......@@ -88,7 +87,7 @@ defactor LoadBalancingExample do
end
reply def nodedown(this, node) do
LoadBalancingExample.disconnect_node(self(), node)
# LoadBalancingExample.disconnect_node(self(), node)
{:noreply, this}
end
end
......@@ -181,7 +180,6 @@ defactor Master do
sync def request_work(this, from, chunk_size, worker_ip) do
Marlon.Utils.visualize(this[:visualization], {:update, Node.self(), "Communicating"})
IO.inspect worker_ip
Marlon.Utils.visualize(this[:visualization], {:update, worker_ip, "Communicating"})
new_pending = this[:pending_request_size] + chunk_size
Worker.notify_wait_time(elem(from,0), new_pending * this[:comm_time])
......
......@@ -33,7 +33,7 @@ defmodule Marlon.Application do
# Check whether this is the node initiated the Marlon system
node_name = Atom.to_string(Node.self())
children = if (String.contains?(node_name, "worker")) do
children = if (String.contains?(node_name, "aux")) do
Logger.info "Starting Marlon on auxiliary node"
[{__MODULE__, []}]
else
......
......@@ -22,7 +22,7 @@ defmodule Marlon.Mixfile do
def project do
[
app: :marlon, # Application ID
app: :marlon,
version: "0.1.0",
elixir: "~> 1.5",
start_permanent: Mix.env == :prod,
......
# Just a Sandbox module for experimentation..
defmodule Sandbox do
use Marlon
def hello do
IO.puts "Hello"
end
def expand_macro do
quoted2 = quote do
defgoal ChunkSizeGoal,
[type: "ESRL",
params:
[exploration_phases: 7,
exploration_steps: 100],
actions: [process_chunk: [1,2,3]],
# action_trigger_fn: fn() -> true end,
# data_trigger_rate: 500,
reward: fn() -> true end
]
end
quoted2 |> Macro.expand_once(__ENV__) |> Macro.to_string()
end
# :observer.start
# LoadBalancing.run_example()
# :timer.sleep(100000000) # !! Otherwise, this process would exit, and any processes linked to it! Probably a better way to do this..
end
# {:ok, pid} = :python.start([{:python_path, '/Users/soft/Documents/Github/AI-Toolbox/build'}])
# :python.call(pid, :sys, :'version.__str__', [])
# IO.inspect :python.call(pid, :marlonEsrl, :createGoal, [3, 0.05, 2000, 7, 100])
# IO.inspect :python.call(pid, :testGuessingGame, :makeGoal, [])
# :python.call(pid, :test, :gameHelp, [])
# System.halt
# LoadBalancingExample.start_link(nil,[name: :example])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment