12.00 72
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SimioAPI;
namespace RunExperiments
{
public partial class RunExperiments : Form
{
privatestatic double_expReturnValue = 0.0;
privatestatic int _currentRun= 0;
publicRunExperiments()
{
InitializeComponent();
}
privatevoid button1_Click(objectsender, EventArgs e)
{
try
{
varreps = Convert.ToInt32(textNumberOfReps.Text);
varruntime = Convert.ToInt32(textDaysPerRun.Text);
vargetFile = new OpenFileDialog();
getFile.Filter = "Simio Project Files(*.spfx)|*.spfx";
if(getFile.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("Canceled by user.", "Warning", MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
string[]warnings;
ISimioProjectproject = SimioProjectFactory.LoadProject(getFile.FileName,out warnings);
textProjectLoaded.Text =getFile.FileName;
IModelmodel = project.Models["Model"];
IExperimentexperiment = model.Experiments["Experiment1"];
//Specify run times.
IRunSetupsetup = experiment.RunSetup;
setup.StartingTime = new DateTime(2010,10, 01);
setup.WarmupPeriod = TimeSpan.FromHours(0);
setup.EndingTime =experiment.RunSetup.StartingTime + TimeSpan.FromDays(runtime);
//Add event handler for ScenarioEnded
experiment.ScenarioEnded += new EventHandler<ScenarioEndedEventArgs>(experiment_ScenarioEnded);
experiment.RunCompleted += new EventHandler<RunCompletedEventArgs>(experiment_RunCompleted);
textResults.Text = "Start!!!" + "\r\n";
//For each number of runs
for(int i = 0; i < experiment.Scenarios.Count;i++)
{
experiment.Scenarios[i].ReplicationsRequired = reps;
}
textResults.Text += "Start run: " + DateTime.Now.ToString()+ " \r\n";
//set table parameter value
model.Tables["Parameters"].Rows[0].Properties["Column1"].Value =_currentRun.ToString(System.Globalization.CultureInfo.InvariantCulture);
//Reset _expReturnValue
_expReturnValue = 0.0;
experiment.Scenarios[0].ReplicationsRequired = reps;
//Run Experiment
experiment.RunAsync();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
voidexperiment_RunCompleted(object sender, RunCompletedEventArgs e)
{
textResults.Text += "End run: " + DateTime.Now.ToString()+ " return value: " +_expReturnValue.ToString() + "\r\n";
IExperimentexperiment = (IExperiment)sender;
experiment.Reset();
}
voidexperiment_ScenarioEnded(object sender, ScenarioEndedEventArgs e)
{
IExperimentexperiment = (IExperiment)sender;
// get responsevalue
foreach(IExperimentResponse response in experiment.Responses)
{
doubleresponseValue = 0.0;
if(e.Scenario.GetResponseValue(response, refresponseValue))
{
_expReturnValue += responseValue;
textResults.Text += "End scenario(" + e.Scenario.Name + ") " + DateTime.Now.ToString()+ " return value: " +responseValue.ToString() + "\r\n";
break;
}
}
}
}
}
using System;
using System.Windows.Forms;
namespace RunExperiments
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[]args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RunExperiments());
}
}
}
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-priority:99;mso-style-qformat:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:"Calibri","sans-serif";mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;mso-font-kerning:1.0pt;}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using SimioAPI;
namespace RunExperiments
{
public partial class RunExperiments : Form
{
privatestatic double_expReturnValue = 0.0;
privatestatic int _currentRun= 0;
publicRunExperiments()
{
InitializeComponent();
}
privatevoid button1_Click(objectsender, EventArgs e)
{
try
{
varreps = Convert.ToInt32(textNumberOfReps.Text);
varruntime = Convert.ToInt32(textDaysPerRun.Text);
vargetFile = new OpenFileDialog();
getFile.Filter = "Simio Project Files(*.spfx)|*.spfx";
if(getFile.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("Canceled by user.", "Warning", MessageBoxButtons.OK,MessageBoxIcon.Warning);
return;
}
string[]warnings;
ISimioProjectproject = SimioProjectFactory.LoadProject(getFile.FileName,out warnings);
textProjectLoaded.Text =getFile.FileName;
IModelmodel = project.Models["Model"];
IExperimentexperiment = model.Experiments["Experiment1"];
//Specify run times.
IRunSetupsetup = experiment.RunSetup;
setup.StartingTime = new DateTime(2010,10, 01);
setup.WarmupPeriod = TimeSpan.FromHours(0);
setup.EndingTime =experiment.RunSetup.StartingTime + TimeSpan.FromDays(runtime);
//Add event handler for ScenarioEnded
experiment.ScenarioEnded += new EventHandler<ScenarioEndedEventArgs>(experiment_ScenarioEnded);
experiment.RunCompleted += new EventHandler<RunCompletedEventArgs>(experiment_RunCompleted);
textResults.Text = "Start!!!" + "\r\n";
//For each number of runs
for(int i = 0; i < experiment.Scenarios.Count;i++)
{
experiment.Scenarios[i].ReplicationsRequired = reps;
}
textResults.Text += "Start run: " + DateTime.Now.ToString()+ " \r\n";
//set table parameter value
model.Tables["Parameters"].Rows[0].Properties["Column1"].Value =_currentRun.ToString(System.Globalization.CultureInfo.InvariantCulture);
//Reset _expReturnValue
_expReturnValue = 0.0;
experiment.Scenarios[0].ReplicationsRequired = reps;
//Run Experiment
experiment.RunAsync();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
voidexperiment_RunCompleted(object sender, RunCompletedEventArgs e)
{
textResults.Text += "End run: " + DateTime.Now.ToString()+ " return value: " +_expReturnValue.ToString() + "\r\n";
IExperimentexperiment = (IExperiment)sender;
experiment.Reset();
}
voidexperiment_ScenarioEnded(object sender, ScenarioEndedEventArgs e)
{
IExperimentexperiment = (IExperiment)sender;
// get responsevalue
foreach(IExperimentResponse response in experiment.Responses)
{
doubleresponseValue = 0.0;
if(e.Scenario.GetResponseValue(response, refresponseValue))
{
_expReturnValue += responseValue;
textResults.Text += "End scenario(" + e.Scenario.Name + ") " + DateTime.Now.ToString()+ " return value: " +responseValue.ToString() + "\r\n";
break;
}
}
}
}
}
using System;
using System.Windows.Forms;
namespace RunExperiments
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[]args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RunExperiments());
}
}
}
Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-priority:99;mso-style-qformat:yes;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:"Calibri","sans-serif";mso-ascii-font-family:Calibri;mso-ascii-theme-font:minor-latin;mso-hansi-font-family:Calibri;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;mso-font-kerning:1.0pt;}