/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2021 JaamSim Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.basicsim;

/**
 * An individual run for a simulation model.
 * @author Harry King
 *
 */
public class SimRun implements RunListener {

	private final int scenarioNumber;     // scenario number
	private final int replicationNumber;  // replication number
	private JaamSimModel simModel;        // simulation model to be executed
	private final RunListener listener;   // listens for the end of the run

	/**
	 * Constructs a SimRun object for the given scenario and replications numbers.
	 * @param scene - scenario number for the run
	 * @param rep - replication number for the run
	 * @param l - listens for the end of the run
	 */
	public SimRun(int scene, int rep, RunListener l) {
		scenarioNumber = scene;
		replicationNumber = rep;
		listener = l;
	}

	/**
	 * Sets the JaamSimModel to be executed for the run.
	 * The model must be configured already and may have been used for a previous run.
	 * @param model - pre-configured simulation model
	 */
	public void setJaamSimModel(JaamSimModel model) {
		simModel = model;
	}

	public JaamSimModel getJaamSimModel() {
		return simModel;
	}

	public int getScenarioNumber() {
		return scenarioNumber;
	}

	public int getReplicationNumber() {
		return replicationNumber;
	}

	/**
	 * Starts the simulation run on a new thread.
	 */
	public void start(double pauseTime) {

		// Reset the scenario and replication numbers
		simModel.setScenarioNumber(scenarioNumber);
		simModel.setReplicationNumber(replicationNumber);

		// Clear the model prior to the next run
		simModel.getEventManager().clear();
		simModel.killGeneratedEntities();

		// Start the run
		simModel.setRunListener(this);
		simModel.start(pauseTime);
	}

	@Override
	public void runEnded() {
		listener.runEnded();
	}

}

@@ -670,16 +670,97 @@
 icsim;%0A%0A
+import java.util.ArrayList;%0A%0Aimport com.jaamsim.StringProviders.StringProvider;%0A%0A
 /**%0A * A
@@ -1140,16 +1140,117 @@
  the run
+%0A%09private final ArrayList%3CDouble%3E runOutputValues;%0A%09private final ArrayList%3CString%3E runOutputStrings;
 %0A%0A%09/**%0A%09
@@ -1595,16 +1595,95 @@
 er = l;%0A
+%09%09runOutputValues = new ArrayList%3C%3E();%0A%09%09runOutputStrings = new ArrayList%3C%3E();%0A
 %09%7D%0A%0A%09/**
@@ -2636,29 +2636,598 @@
 ) %7B%0A
-%09%09listener.runEnded()
+%0A%09%09// Save the RunOutputList values for the run%0A%09%09double simTime = simModel.getSimTime();%0A%09%09ArrayList%3CStringProvider%3E runOutputList = simModel.getSimulation().getRunOutputList().getValue();%0A%09%09for (int i = 0; i %3C runOutputList.size(); i++) %7B%0A%09%09%09runOutputValues.add(runOutputList.get(i).getNextValue(simTime));%0A%09%09%09runOutputStrings.add(runOutputList.get(i).getNextString(simTime));%0A%09%09%7D%0A%0A%09%09// Notify the listener%0A%09%09listener.runEnded();%0A%09%7D%0A%0A%09public ArrayList%3CDouble%3E getRunOutputValues() %7B%0A%09%09return runOutputValues;%0A%09%7D%0A%0A%09public ArrayList%3CString%3E getRunOutputStrings() %7B%0A%09%09return runOutputStrings
 ;%0A%09%7D

save the RunOutputList values for a completed SimRun