Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/OFFIS-DAI/cosima into com…
Browse files Browse the repository at this point in the history
…munication-robustness

# Conflicts:
#	cosima_omnetpp_project/networks/TrafficNetwork.ned
  • Loading branch information
Frost, Emilie committed Jul 12, 2024
2 parents 4bc0ddc + 357dc2b commit 71ef315
Show file tree
Hide file tree
Showing 4 changed files with 673 additions and 19 deletions.
42 changes: 23 additions & 19 deletions cosima_core/scenarios/mango/mango_cohda_scenario.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import time
from copy import deepcopy
from os import listdir
import pandas as pd
Expand All @@ -15,7 +14,7 @@
import cosima_core.util.general_config as cfg
from cosima_core.util.scenario_setup_util import ScenarioHelper
from cosima_core.util.util_functions import get_host_names
from scenario_config import NUMBER_OF_AGENTS
from scenario_config import NUMBER_OF_AGENTS, TRAFFIC_CONFIGURATION, USE_COMMUNICATION_SIMULATION

codec = JSON()
for serializer in cohda_serializers:
Expand All @@ -25,17 +24,7 @@
# [3200, 3200, 3200, 3200, 4000], same weight
# Target 20 agents DayAhead:
# [4000, 4000, 4000, 4000, 4000], same weight
target = ([110, 110, 110, 110, 110], [1, 1, 1, 1, 1, ],)

s_array = [
[
[1, 1, 1, 1, 1],
[4, 3, 3, 3, 3],
[6, 6, 6, 6, 6],
[9, 8, 8, 8, 8],
[11, 11, 11, 11, 11],
]
]
target = ([3200 * NUMBER_OF_AGENTS/20 for _ in range(4)], [1, 1, 1, 1])


def main():
Expand All @@ -44,17 +33,25 @@ def main():
'ContainerSim': {
'python': 'cosima_core.simulators.mango_example.container_sim:ContainerSimulator',
},
'ICTController': {
'python': 'cosima_core.simulators.ict_controller_simulator:ICTController'},
}

start = time.time()

scenario_helper = ScenarioHelper()
world, communication_simulator, client_attribute_mapping, sim_config = \
scenario_helper.prepare_scenario(sim_config=sim_config)

# adapt maximal byte size per msg group, since message get bigger if more agents are involved
# TODO: change for other number of agents
cfg.MAX_BYTE_SIZE_PER_MSG_GROUP = 10000
cfg.MAX_BYTE_SIZE_PER_MSG_GROUP = 30000

use_ict_simulator = (len(TRAFFIC_CONFIGURATION) > 0 and USE_COMMUNICATION_SIMULATION)

if use_ict_simulator:
ict_controller = world.start('ICTController',
infrastructure_changes=[],
traffic_configuration=TRAFFIC_CONFIGURATION).ICT()


filenames = listdir(cfg.CHP_DATA)
all_schedule_names = [filename for filename in filenames if filename.startswith("CHP")]
Expand Down Expand Up @@ -104,7 +101,8 @@ def schedule_provider(i):
# is normal participant
cohda_roles.append(NegotiationTerminationParticipantRole())

cohda_roles.append(COHDANegotiationRole(lambda: s_array[0], lambda s: True))
cohda_roles.append(COHDANegotiationRole(schedules_provider=schedule_provider(idx),
local_acceptable_func=lambda s: True))
cohda_roles.append(CoalitionParticipantRole())

agent_models[current_container_name] = \
Expand All @@ -120,14 +118,20 @@ def schedule_provider(i):
world.connect(agent_models[name], communication_simulator, f'message', weak=True)
world.connect(communication_simulator, agent_models[name], client_attribute_mapping[name])

if use_ict_simulator:
# connect ict controller with communication_simulator
world.connect(ict_controller, communication_simulator, f'ict_message', weak=True)
world.connect(communication_simulator, ict_controller, f'ctrl_message')

# set initial event
world.set_initial_event(agent_models['client0'].sid, time=0)

if use_ict_simulator:
world.set_initial_event(ict_controller.sid)

scenario_helper.run_simulation()
scenario_helper.shutdown_simulation()

print('time: ', time.time() - start)


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions cosima_core/simulators/ict_controller_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def get_data(self, outputs):
'sim_time': event['start'],
'source': event['source'],
'destination': event['destination'],
'start': event['start'],
'stop': event['stop'],
'interval': event['interval'],
'packet_length': event['packet_length']
Expand Down
14 changes: 14 additions & 0 deletions cosima_omnetpp_project/modules/CosimaScheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,18 @@ int CosimaScheduler::handleMsgFromCoupledSimulation(std::vector<char> data) {
log("Setting logging level to: " + loggingLevelStr, "info");
MAX_BYTE_SIZE_PER_MSG = initialMessage.max_byte_size_per_msg_group();
log("Setting max byte size per message to " + std::to_string(MAX_BYTE_SIZE_PER_MSG));

// schedule max advance event
auto maxAdvance = (initialMessage.max_advance() * 1.0)/1000;
schedulerModuleObject->cancelMaxAdvanceEvent();
schedulerModuleObject->maxAdvEvent->setCtrlType(ControlType::MaxAdvance);
if (maxAdvance >= simTime().dbl()) {
schedulerModuleObject->maxAdvEvent->setArrival(schedulerModule->getId(), -1, maxAdvance);
getSimulation()->getFES()->insert(schedulerModuleObject->maxAdvEvent);
log("CosimaScheduler: max advanced event inserted for time " + std::to_string(maxAdvance) + " at simtime " + simTime().str());
} else {
log("max advance " + std::to_string(maxAdvance) + " at time " + simTime().str() + " not inserted");
}
}

// get info messages
Expand Down Expand Up @@ -552,6 +564,8 @@ int CosimaScheduler::handleMsgFromCoupledSimulation(std::vector<char> data) {
trafficEvent->setArrival(scenarioManagerObject->getId(), -1, arrivalTime);
log("CosimaScheduler: traffic event inserted for simtime " + std::to_string(arrivalTime) + " for " + trafficMessage.source() + " to " + trafficMessage.destination() + ".");
getSimulation()->getFES()->insert(trafficEvent);
insertedEvent = true;
eventScheduled = true;
}

for(auto i=0; i < pmsg_group.attack_messages().size(); i++) {
Expand Down
Loading

0 comments on commit 71ef315

Please sign in to comment.