[*] Запустить функцию по требованию
[*] Получите значение. /> < /ul>
В API нет функции «пауза», только остановка и вариации выполнения. Я думал о основном цикле каждый времена, который ожидает движения внешнего сигнала.
Код: Выделить всё
# Air Defence Tutorial Simulation
from anylogiccloudclient.client.cloud_client import CloudClient
def _intermittant_run(s,dt):
while s.get_progress()["total"] < 100:
print("Progress: " + str(s.get_progress()["total"]) + "%")
print(s.get_status())
time.sleep(dt)
client = CloudClient(ANYLOGIC_API_KEY)
# print(client)
MODEL = client.get_model_by_name(MODEL_NAME)
print ('=== Model opened ===')
params = { "P radar 2 range": 300, }
version = client.get_latest_model_version(MODEL_NAME)
inputs = client.create_inputs_from_experiment(version, EXPERIMENT_ID)
print ('=== Changed inputs ===')
inputs.set_input("P radar 2 range", 175)
inputs.set_input("{STOP_TIME}", 54321)
# inputs.set_input("P_SIM_PAUSED", False)
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
simulation = client.create_simulation(inputs)
# It does not wait for the simulation to complete:
simulation.run()
dt = 1.033
progress_thread = threading.Thread(target=_intermittant_run, args=(simulation,dt,))
# initiates a repeated call of s.get_progress(), which returns information about the progress.
progress_thread.start()
print ('=== Running the simulation ... ===')
polling_period = 1000 # msec
print(simulation.get_status())
for step in range(10):
print('running step ',step)
inputs.set_input("P radar 2 range", 10*step)
# simulation.wait_for_completion()
simulation.wait_for_completion(polling_period)
print("P radar 2 range is ",inputs.get_input("P radar 2 range"))
print(simulation.get_status())
print ('=== Simulation is terminated ===')
outputs = simulation.get_outputs()
gleb
Подробнее здесь: https://stackoverflow.com/questions/796 ... python-api