Browse Source

ignore examples

Snej69420 7 months ago
parent
commit
b9c36dfb47

+ 2 - 0
.juliaignore

@@ -0,0 +1,2 @@
+Agents/
+DEVS/

src/Agents/PolicedTrafficLight/Model.jl → Agents/PolicedTrafficLight/Model.jl


src/Agents/PolicedTrafficLight/Police.jl → Agents/PolicedTrafficLight/Police.jl


src/Agents/PolicedTrafficLight/TrafficLight.jl → Agents/PolicedTrafficLight/TrafficLight.jl


src/Agents/PolicedTrafficLight_DEVS/PoliceAgent.jl → Agents/PolicedTrafficLight_DEVS/PoliceAgent.jl


src/Agents/PolicedTrafficLight_DEVS/TrafficLight.jl → Agents/PolicedTrafficLight_DEVS/TrafficLight.jl


src/Agents/PolicedTrafficLight_DEVS/TrafficModel.jl → Agents/PolicedTrafficLight_DEVS/TrafficModel.jl


src/Agents/TrafficLight/TrafficLight.jl → Agents/TrafficLight/TrafficLight.jl


src/Agents/TrafficLight/TrafficLightCont.jl → Agents/TrafficLight/TrafficLightCont.jl


src/Agents/run.jl → Agents/run.jl


src/Agents/run_CoupledDEVS.jl → Agents/run_CoupledDEVS.jl


src/Agents/run_DEVS.jl → Agents/run_DEVS.jl


src/DEVS/PolicedTrafficLight/Police.py → DEVS/PolicedTrafficLight/Police.py


+ 2 - 2
src/DEVS/PolicedTrafficLight/PolicedTraffic.py

@@ -1,6 +1,6 @@
 from pypdevs.DEVS import CoupledDEVS
-from DEVS.PolicedTrafficLight.Police import PoliceAgent
-from DEVS.PolicedTrafficLight.TrafficLight import TrafficLight
+from src.DEVS.PolicedTrafficLight.Police import PoliceAgent
+from src.DEVS.PolicedTrafficLight.TrafficLight import TrafficLight
 
 class PolicedTraffic(CoupledDEVS):
     def __init__(self):

src/DEVS/PolicedTrafficLight/TrafficLight.py → DEVS/PolicedTrafficLight/TrafficLight.py


src/DEVS/TrafficLight.py → DEVS/TrafficLight.py


+ 1 - 2
src/DEVS/run.py

@@ -1,6 +1,5 @@
 from pypdevs.simulator import Simulator
-from DEVS.TrafficLight import TrafficLight
-from DEVS.PolicedTrafficLight.PolicedTraffic import PolicedTraffic
+from src.DEVS.PolicedTrafficLight.PolicedTraffic import PolicedTraffic
 
 if __name__ == "__main__":
     # model = TrafficLight()

+ 1 - 0
Project.toml

@@ -1,5 +1,6 @@
 name = "DEVS2Agents"
 uuid = "073a0784-fe80-4c04-b3c3-fb0686668e26"
+authors = ["Jens Vissenberg jens.vissenberg@student.uantwerpen.be"]
 version = "0.1.0"
 
 [deps]

+ 0 - 69
src/DEVStone/DelayedAtomic.jl

@@ -1,69 +0,0 @@
-using Agents
-
-@enum State Passive=1 Active=2
-
-struct Message <: DEVSMessage
-    activate::Int
-end
-
-function julia_stones(delay::Float64)
-    val = 0.0
-    for i in 1:Int(round(delay))
-        val += sin(i)
-    end
-    return val
-end
-
-@agent struct DelayedAtomic(AtomicDEVS)
-    state::State = Passive
-    int_delay::Float64 = 0.0
-    ext_delay::Float64 = 0.0
-    prep_time::Float64 = 0.0
-    has_out_port::Bool = false
-
-    stats::Bool = false
-    int_count::Int = 0
-    ext_count::Int = 0
-end
-
-format_state(agent::DelayedAtomic) = "State.$(agent.state)"
-format_message(msg::Message) = "$(msg.activate)"
-
-function setup_ports!(agent::DelayedAtomic)
-    add_in_port!(agent, :i_in)
-    if agent.has_out_port
-        add_out_port!(agent, :o_out)
-    end
-end
-
-function time_advance(agent::DelayedAtomic, model)
-    return agent.state == Active ? agent.prep_time : Inf
-end
-
-function internal_transition!(agent::DelayedAtomic, model)
-    agent.stats && (agent.int_count += 1)
-    agent.int_delay > 0.0 && julia_stones(agent.int_delay)
-    agent.state = Passive
-end
-
-function external_transition!(agent::DelayedAtomic, model, e, bag)
-    agent.stats && (agent.ext_count += 1)
-    agent.ext_delay > 0.0 && julia_stones(agent.ext_delay)
-    agent.state = Active
-end
-
-function confluent_transition!(agent::DelayedAtomic, model, bag)
-    internal_transition!(agent, model)
-    external_transition!(agent, model, 0.0, bag)
-end
-
-function output!(agent::DelayedAtomic, model)
-    if agent.has_out_port
-        return (
-            (
-                :o_out, (Message(0), )
-            ),
-        )
-    end
-    return nothing
-end

+ 0 - 67
src/DEVStone/Generator.jl

@@ -1,67 +0,0 @@
-module GeneratorModel
-    using Agents
-    using ..Atomic
-
-    @enum GenState Waiting=1 Active=2 Passive=3
-
-    struct Message <: DEVSMessage
-        activate::UnitRange{Int}
-    end
-
-    @agent struct Generator(AtomicDEVS)
-        num_outputs::Int = 1
-        period::Float64 = 1.0
-        cycles::Int = 1
-        current_cycle::Int = 0
-        state::GenState = Waiting
-    end
-
-    Atomic.format_state(gen::Generator) = "State.$(gen.state)_Cycle.$(gen.current_cycle)"
-    Atomic.format_message(msg::Message) = "$(msg.activate)"
-
-    function Atomic.setup_ports!(gen::Generator)
-        Atomic.add_out_port!(gen, :o_out)
-    end
-
-    function Atomic.time_advance(gen::Generator, model)
-        if gen.state == Active
-            return 0.0
-        elseif gen.state == Waiting
-            return gen.period
-        else
-            return Inf
-        end
-    end
-
-    function Atomic.internal_transition!(gen::Generator, model)
-        if gen.current_cycle >= gen.cycles
-            gen.state = Passive
-        elseif gen.state == Active
-            gen.state = Waiting
-            gen.current_cycle += 1
-        elseif gen.state == Waiting
-            gen.state = Active
-        else
-            gen.state = Passive
-        end
-    end
-
-    function Atomic.external_transition!(gen::Generator, model, e, bag)
-        return nothing
-    end
-
-    function Atomic.confluent_transition!(gen::Generator, model, bag)
-        Atomic.internal_transition!(gen, model)
-    end
-
-    function Atomic.output!(gen::Generator, model)
-        if gen.state == Active
-            return (
-                (
-                    :o_out, (Message(0:(gen.num_outputs - 1)),
-                )),
-            )
-        end
-        return nothing
-    end
-end

+ 0 - 101
src/DEVStone/Topologies.jl

@@ -1,101 +0,0 @@
-module DEVStoneTopologies
-    using ..Atomic
-    using ..Coupled
-    using ..BaseAtomic
-
-    export build_devstone, Structure, LI, HI, HO
-
-    @enum Structure LI HI HO
-
-    function build_devstone(type::Structure, name::String, depth::Int, width::Int, int_delay::Float64, ext_delay::Float64, stats::Bool=false)
-        if depth < 1 || width < 1
-            error("Invalid depth or width")
-        end
-
-        top_model = CoupledDEVS(name)
-        has_out_port = type == HI || type == HO
-
-        add_in_port!(top_model, :i_in)
-        if has_out_port
-            add_out_port!(top_model, :o_out)
-        end
-        if type == HO
-            add_in_port!(top_model, :i_in2)
-            add_out_port!(top_model, :o_out2)
-        end
-
-        # Leaf
-        if depth == 1
-            p_time = round(rand() + 1.0, digits=3)
-            atom = add_submodel!(top_model, "Atomic_0_0", BaseAtomic.DelayedAtomic;
-                int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
-                has_out_port, stats=stats)
-
-            connect!(top_model, self.i_in, atom.i_in)
-            if has_out_port
-                connect!(top_model, atom.o_out, self.o_out)
-            end
-
-            return top_model
-        end
-
-        child_name = "Coupled_$(depth - 1)"
-        child_coupled = build_devstone(type, child_name, depth - 1, width, int_delay, ext_delay, stats)
-        child = add_submodel!(top_model, child_name, child_coupled)
-
-        connect!(top_model, self.i_in, child.i_in)
-        if type == HO
-            connect!(top_model, self.i_in, child.i_in2)
-        end
-
-        if has_out_port
-            connect!(top_model, child.o_out, self.o_out)
-        end
-
-        width_models = ModelRef[]
-        for idx in 0:(width - 2)
-            p_time = 1.0 - round(rand() * (0.5 / width) + (idx / width), digits=3)
-            atomic_name = "Atomic_$(depth - 1)_$(idx)"
-
-            atom = add_submodel!(top_model, atomic_name, BaseAtomic.DelayedAtomic;
-                int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
-                has_out_port=has_out_port, stats=stats)
-
-            push!(width_models, atom)
-        end
-
-        if type == LI
-            for atom in width_models
-                connect!(top_model, self.i_in, atom.i_in)
-            end
-
-        elseif type == HI
-            for atom in width_models
-                connect!(top_model, self.i_in, atom.i_in)
-            end
-
-            # Chain atomics
-            for i in 1:(length(width_models) - 1)
-                connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in)
-            end
-
-        elseif type == HO
-            for i in 1:(length(width_models) - 1)
-                curr_atom = width_models[i]
-                next_atom = width_models[i + 1]
-
-                connect!(top_model, curr_atom.o_out, next_atom.i_in)
-                connect!(top_model, self.i_in2, curr_atom.i_in)
-                connect!(top_model, curr_atom.o_out, self.o_out2)
-            end
-
-            if length(width_models) > 0
-                last_atom = width_models[end]
-                connect!(top_model, self.i_in2, last_atom.i_in)
-                connect!(top_model, last_atom.o_out, self.o_out2)
-            end
-        end
-
-        return top_model
-    end
-end

+ 0 - 192
src/DEVStone/main.jl

@@ -1,192 +0,0 @@
-include("../Framework/AtomicDEVS.jl")
-include("../Framework/CoupledDEVS.jl")
-include("DelayedAtomic.jl")
-include("Generator.jl")
-include("Topologies.jl")
-
-using Agents
-using ArgParse
-using Profile
-using ProfileView
-using .Atomic, .Coupled, .BaseAtomic, .GeneratorModel, .DEVStoneTopologies
-
-function build_environment(type::Structure, devstone_model::CoupledDEVS, gen_period::Float64, num_outputs::Int)
-    env = CoupledDEVS("DEVStoneEnvironment")
-    add_submodel!(env, :generator, GeneratorModel.Generator;
-        num_outputs = num_outputs, period = gen_period, cycles = 1)
-    add_submodel!(env, :devstone, devstone_model)
-
-    connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in)
-    if type == HO
-        connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2)
-    end
-    return env
-end
-
-function parse_commandline()
-    s = ArgParseSettings(description = "Julia DEVS Orchestrator and Benchmarker")
-
-    @add_arg_table! s begin
-        "--path", "-p"
-            help = "Path to the results directory"
-            default = "./Results-Julia"
-        "--filename", "-f"
-            help = "Name of the output file suffix"
-            default = ""
-        "--append", "-a"
-            help = "Append to the output file instead of overwriting."
-            action = :store_true
-        "--max-depth", "-D"
-            help = "Max depth for the generated models"
-            arg_type = Int
-            default = 8
-        "--depth-stepsize"
-            help = "Determines for which depths a model is generated."
-            arg_type = Int
-            default = 0 # Will be mapped to max-depth later if 0
-        "--max-width", "-W"
-            help = "Max width for the generated models"
-            arg_type = Int
-            default = 8
-        "--width-stepsize"
-            help = "Determines for which widths a model is generated."
-            arg_type = Int
-            default = 0 # Will be mapped to max-width later if 0
-        "--repetitions", "-r"
-            help = "The number of times a simulation is repeated"
-            arg_type = Int
-            default = 1
-        "--output", "-O"
-            help = "Print Simulation Outputs to console"
-            action = :store_true
-        "--stats", "-S"
-            help = "Enable Event Tracking"
-            action = :store_true
-        "--logging", "-L"
-            help = "Enables and print model traces to the console"
-            action = :store_true
-        "--model-structure", "-m"
-            help = "List of structures to run (e.g., LI HI HO)"
-            nargs = '*'
-            default = ["LI", "HI", "HO"]
-    end
-
-    return parse_args(s)
-end
-
-# --- Single Simulation Runner ---
-function run_single_simulation(topology_type::Structure, type_str::String, depth::Int, width::Int, stats::Bool, logging::Bool)
-    int_delay = 0.0
-    ext_delay = 0.0
-
-    # Model Creation
-    start_time = time()
-    devstone_model = build_devstone(topology_type, "DEVStone_$(type_str)", depth, width, int_delay, ext_delay, stats)
-    env = build_environment(topology_type, devstone_model, Float64(width), 1)
-    model_created_time = time()
-
-    # Setup
-    AgentUnion = Union{BaseAtomic.DelayedAtomic, GeneratorModel.Generator}
-    model = compile_devs(env, AgentUnion, (Atomic.UniversalEvent, ); logging)
-    engine_setup_time = time()
-
-#     simulate_devs!(warmup)
-#     model = compile_devs(env, AgentUnion, (Atomic.UniversalEvent, ); logging=false)
-
-#     Profile.clear()
-
-    # Simulate
-    simulate_devs!(model)
-#     @profile simulate_devs!(model)
-    sim_time = time()
-#     Profile.print(format=:flat, sortedby=:count)
-
-    t_creation = model_created_time - start_time
-    t_setup = engine_setup_time - model_created_time
-    t_sim = sim_time - engine_setup_time
-
-    return t_creation, t_setup, t_sim, model
-end
-
-# --- Orchestrator Main ---
-function main()
-    args = parse_commandline()
-    stats = args["stats"]
-    logging = args["logging"]
-
-    # Process step sizes
-    ds = args["depth-stepsize"] > 0 ? args["depth-stepsize"] : args["max-depth"]
-    ws = args["width-stepsize"] > 0 ? args["width-stepsize"] : args["max-width"]
-
-    # Setup directories
-    time_dir = joinpath(args["path"], "Time", "parallel")
-    mkpath(time_dir)
-
-    # Convert string inputs to Enum
-    struct_map = Dict("LI" => LI, "HI" => HI, "HO" => HO)
-
-    for model_str in args["model-structure"]
-        if !haskey(struct_map, model_str)
-            println("Skipping unknown structure: $model_str")
-            continue
-        end
-        topology_type = struct_map[model_str]
-
-        # Construct filename
-        suffix = args["filename"] == "" ? "" : "_$(args["filename"])"
-        file_path = joinpath(time_dir, "$(model_str)$(suffix).csv")
-        file_mode = args["append"] ? "a" : "w"
-
-        # Open CSV
-        open(file_path, file_mode) do file
-            # Write Header if new file
-            if !args["append"] || filesize(file_path) == 0
-                write(file, "model_type,depth,width,run,creation_time,setup_time,simulation_time\n")
-            end
-
-            # Grid Search Loop
-            repetitions = args["repetitions"]
-            for depth in ds:ds:args["max-depth"]
-                for width in ws:ws:args["max-width"]
-                    for run in 0:(repetitions - 1)
-                        if args["output"]
-                            println("Running $model_str (D:$depth, W:$width) - Repetition $run...")
-                        end
-
-                        # WARM-UP PASS (Only for the very first execution of the script to compile)
-                        if run == 0 && depth == ds && width == ws && repetitions != 1
-                            run_single_simulation(topology_type, model_str, 2, 2, false, false)
-                        end
-
-                        # Actual measured run
-                        t_creation, t_setup, t_sim, model = run_single_simulation(topology_type, model_str, depth, width, stats, logging)
-
-                        # Log to CSV
-                        write(file, "$model_str,$depth,$width,$run,$t_creation,$t_setup,$t_sim\n")
-
-                        if args["output"] || args["stats"]
-                            println("  Creation: $(round(t_creation, digits=4))s | Setup: $(round(t_setup, digits=4))s | Sim: $(round(t_sim, digits=4))s")
-                        end
-                        if args["stats"]
-                            total_int = 0
-                            total_ext = 0
-                            for agent in allagents(model)
-                                if agent isa BaseAtomic.DelayedAtomic
-                                    total_int += agent.int_count
-                                    total_ext += agent.ext_count
-                                end
-                            end
-                            println("  Total internal transitions: $total_int")
-                            println("  Total external transitions: $total_ext")
-                            println("  Total Number of Transitions: $(total_int + total_ext)")
-                            println("  " * "-"^48)
-                        end
-                    end
-                end
-            end
-        end
-        println("✅ Saved timing results to $file_path")
-    end
-end
-
-main()