Esempio n. 1
0
        /// <summary>
        /// Initialize, which means setting the ExtensionsPath and loading the project.
        /// If there are warnings, they are placed in LoadWarningsList.
        /// </summary>
        /// <param name="extensionsPath"></param>
        /// <param name="projectFullPath"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public bool Initialize(string extensionsPath, out string explanation)
        {
            explanation = "";
            string marker = "Checking extension and project paths.";

            try
            {
                if (Directory.Exists(extensionsPath) == false)
                {
                    explanation = $"ExtensionsPath={extensionsPath} not found.";
                    return(false);
                }

                ExtensionsPath = extensionsPath;

                marker = $"Setting extensions path={extensionsPath}";
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Failed to initialize HeadlessContext. ExtensionsPath={extensionsPath} Err={ex.Message}";
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize, which means setting the ExtensionsPath and loading the project.
        /// If there are warnings, they are placed in LoadWarningsList.
        /// </summary>
        /// <param name="projectFullPath"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public bool LoadProject(string projectFullPath, out string explanation)
        {
            explanation = "";
            string marker = "Checking extension and project paths.";

            if (ExtensionsPath == null)
            {
                explanation = $"Cannot LoadProject with null ExtensionsPath";
                return(false);
            }

            try
            {
                // If File Not Exist, Throw Exception
                if (File.Exists(projectFullPath) == false)
                {
                    explanation = $"Project File={projectFullPath} not found.";
                    return(false);
                }

                ProjectPath = projectFullPath;

                marker = $"Setting extensions path={ExtensionsPath}";
                SimioProjectFactory.SetExtensionsPath(ExtensionsPath); // No harm in doing it again.

                // Open project file.
                marker         = $"Loading Project={projectFullPath}.";
                CurrentProject = SimioProjectFactory.LoadProject(projectFullPath, out string[] warnings);

                ProjectLoadErrorList = null;
                if (warnings.Length > 0)
                {
                    ProjectLoadErrorList = new List <string>();
                    foreach (string warning in warnings)
                    {
                        ProjectLoadErrorList.Add(warning);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Failed to LoadProject={projectFullPath} Err={ex.Message}";
                return(false);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Set the extensions path and then Load the project file and return a SimioProject.
        /// </summary>
        /// <param name="projectFullPath"></param>
        public static ISimioProject LoadProject(string extensionsPath, string projectFullPath, out string explanation)
        {
            explanation = "";
            string marker = "Begin.";

            string[] warnings;

            try
            {
                // If File Not Exist, Throw Exeption
                if (File.Exists(projectFullPath) == false)
                {
                    explanation = $"Project File={projectFullPath} not found.";
                    return(null);
                }

                if (Directory.Exists(extensionsPath) == false)
                {
                    explanation = $"ExtensionsPath={extensionsPath} not found.";
                    return(null);
                }

                marker = $"Setting extensions path={extensionsPath}";
                LogIt($"Info: {marker}");
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                // Open project file.
                marker = $"Loading Project={projectFullPath}.";
                LogIt($"Info: {marker}");
                ISimioProject simioProject = SimioProjectFactory.LoadProject(projectFullPath, out warnings);

                marker = $"Loaded Project={projectFullPath} with {warnings.Count()} warnings.";
                int ii = 1;
                foreach (string warning in warnings)
                {
                    LogIt($"Warning: {ii++}{warning}");
                }

                return(simioProject);
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Cannot load={projectFullPath} Err={ex.Message}");
            }
        }
        /// <summary>
        /// Run an experiment. The experiment is Reset prior to run.
        /// </summary>
        /// <param name="extensionsPath"></param>
        /// <param name="sourceProjectPath"></param>
        /// <param name="saveProjectPath"></param>
        /// <param name="experimentName"></param>
        /// <param name="modelName"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunModelExperiment(string extensionsPath, string sourceProjectPath, string saveProjectPath,
                                              string modelName, string experimentName,
                                              out string explanation)
        {
            string contextInfo = $"ExtensionsPath={extensionsPath}, ProjectPath={sourceProjectPath}:";
            string marker      = "Begin.";

            try
            {
                // Set an extensions path to where we can locate User Extensions, etc.
                if (string.IsNullOrEmpty(extensionsPath))
                {
                    extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                }

                marker = $"{contextInfo}. Setting Extensions Path...";
                LogIt($"Info: {marker}");
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                marker = $"{contextInfo}. Loading Project...";
                ISimioProject project = LoadProject(extensionsPath, sourceProjectPath, out explanation);
                if (project == null)
                {
                    return(false);
                }

                marker = $"{contextInfo}. Running Experiment...";
                if (RunModelExperiment(project, saveProjectPath, modelName, experimentName, out explanation))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                explanation = $"Marker={marker} Err={ex.Message}";
                return(false);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Run an experiment
        /// </summary>
        /// <param name="projectPathAndFile"></param>
        /// <param name="experimentName"></param>
        /// <param name="saveModelAfterRun"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunExperiment(string projectFullPath, string modelName, string experimentName, bool saveModelAfterRun, out string explanation)
        {
            explanation = "";
            string marker = "Begin";

            try
            {
                // Set an extensions path to where we can locate User Extensions, etc.
                string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                marker = $"Setting Extensions Path to={extensionsPath}";
                LogIt($"Info: {marker}");
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                marker = $"Loading Project from={projectFullPath}";
                ISimioProject project = LoadProject(projectFullPath, out explanation);
                if (project == null)
                {
                    return(false);
                }

                marker = $"Loading Model named={modelName}";
                IModel model = LoadModel(project, modelName, out explanation);
                if (model == null)
                {
                    return(false);
                }

                marker = $"Loading Experiment named={experimentName}";
                IExperiment experiment = LoadExperiment(model, experimentName, out explanation);
                if (experiment == null)
                {
                    return(false);
                }

                // Create some methods to handle experiment events
                experiment.ReplicationEnded += (s, e) =>
                {
                    LogIt($"Info: Event=> Ended Replication={e.ReplicationNumber} of Scenario={e.Scenario.Name}.");
                };

                experiment.ScenarioEnded += (s, e) =>
                {
                    LogIt($"Info: Event=> Scenario={e.Scenario.Name} Ended.");
                };

                experiment.RunCompleted += (s, e) =>
                {
                    LogIt($"Info: Event=> Experiment={experiment.Name} Run Complete. ");
                };

                // Now do the run.
                experiment.Reset();
                experiment.Run();
                //experiment.RunAsync(); // Another option

                if (saveModelAfterRun)
                {
                    marker = $"Save Project After Experiment Run to= (SimioProjectFactory.SaveProject)";
                    LogIt($"Info: {marker}");

                    string[] warnings;
                    SimioProjectFactory.SaveProject(project, projectFullPath, out warnings);
                    foreach (string warning in warnings)
                    {
                        LogIt($"Warning: {warning}");
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Marker={marker} Err={ex}");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Run a model plan
        /// </summary>
        /// <param name="projectPathAndFile"></param>
        /// <param name="modelName"></param>
        /// <param name="runRiskAnalysis"></param>
        /// <param name="saveModelAfterRun"></param>
        /// <param name="publishPlanAfterRun"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunModel(string projectFullPath, string modelName, bool runRiskAnalysis, bool saveModelAfterRun, bool publishPlanAfterRun, out string explanation)
        {
            explanation = "";
            string marker = "Begin";

            string[] warnings;

            try
            {
                // Set an extensions path to where we can locate User Extensions, etc.
                string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                marker = $"Setting Extensions Path to={extensionsPath}";
                LogIt($"Info: {marker}");

                ISimioProject project = null;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    SimioProjectFactory.SetExtensionsPath(extensionsPath);

                    project = LoadProject(projectFullPath, out explanation);
                    if (project == null)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    explanation = $"Cannot load from {projectFullPath}. Err={ex}";
                    return(false);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }

                IModel model = LoadModel(project, modelName, out explanation);
                if (model == null)
                {
                    return(false);
                }

                // Check for Plan
                if (model.Plan == null)
                {
                    explanation = $"Model={model.Name} has no Plan.";
                    return(false);
                }

                // Start Plan
                marker = "Starting Plan (model.Plan.RunPlan)";
                LogIt($"Info: {marker}");
                model.Plan.RunPlan();

                if (runRiskAnalysis)
                {
                    marker = "Plan Finished...Starting Analyze Risk (model.Plan.RunRiskAnalysis)";
                    LogIt($"Info: {marker}");
                    model.Plan.RunRiskAnalysis();
                }
                if (saveModelAfterRun)
                {
                    marker = "Save Project After Schedule Run (SimioProjectFactory.SaveProject)";
                    LogIt($"Info: {marker}");
                    SimioProjectFactory.SaveProject(project, projectFullPath, out warnings);
                }
                if (publishPlanAfterRun)
                {
                    marker = "PublishPlan";
                    LogIt($"Info: {marker}");

                    // ADD PUBLISH PLAN CODE HERE
                }
                marker = "End";


                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Project={projectFullPath} Model={modelName} Marker={marker} Err={ex.Message}";
                Alert(explanation);
                return(false);
            }
        } // RunModel
Esempio n. 7
0
        static void Main(string[] args)
        {
            string simioExtensionPath = @"Extensions";

            SimioProjectFactory.SetExtensionsPath(simioExtensionPath);
        }
Esempio n. 8
0
        /// <summary>
        /// Set the extensionpath, load a project, then the load the model, and run a plan for that model.
        /// </summary>
        /// <param name="extensionsPath">For DLL search. E.g. AppDomain.CurrentDomain.BaseDirectory</param>
        /// <param name="projectPathAndFile"></param>
        /// <param name="modelName"></param>
        /// <param name="runRiskAnalysis"></param>
        /// <param name="saveModelAfterRun"></param>
        /// <param name="publishPlanAfterRun"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunModelPlan(string extensionsPath, string projectFullPath, string modelName, bool runRiskAnalysis, bool saveModelAfterRun, bool publishPlanAfterRun, out string explanation)
        {
            explanation = "";
            string marker = "Begin";

            string[] warnings;

            try
            {
                // Set an extensions path to where we can locate User Extensions, etc.
                if (string.IsNullOrEmpty(extensionsPath))
                {
                    extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    LogIt($"Info: No ExtensionsPath supplied. Defaulting to={extensionsPath}");
                }

                marker = $"Setting Extensions Path to={extensionsPath}";
                LogIt($"Info: {marker}");

                // Load the Project
                ISimioProject project = null;
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    SimioProjectFactory.SetExtensionsPath(extensionsPath);

                    project = LoadProject(extensionsPath, projectFullPath, out explanation);
                    if (project == null)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    explanation = $"Cannot load from {projectFullPath}. Err={ex.Message}";
                    return(false);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }

                // Load the Model
                IModel model = LoadModel(project, modelName, out explanation);
                if (model == null)
                {
                    return(false);
                }

                // Test to see if we can 'cheat'
                IPlan plan = (IPlan)model;
                plan.RunPlan();

                // Check for Plan
                if (model.Plan == null)
                {
                    explanation = $"Model={model.Name} has no Plan (you may not have a license for one)";
                    return(false);
                }

                // Start Plan
                marker = "Starting Plan (model.Plan.RunPlan)";
                LogIt($"Info: {marker}");
                model.Plan.RunPlan();

                IPlan plan2 = (IPlan)model;
                plan2.RunPlan();

                if (runRiskAnalysis)
                {
                    marker = "Plan Finished...Starting Analyze Risk (model.Plan.RunRiskAnalysis)";
                    LogIt($"Info: {marker}");
                    model.Plan.RunRiskAnalysis();
                }
                if (saveModelAfterRun)
                {
                    marker = "Save Project After Schedule Run (SimioProjectFactory.SaveProject)";
                    LogIt($"Info: {marker}");
                    SimioProjectFactory.SaveProject(project, projectFullPath, out warnings);
                }
                if (publishPlanAfterRun)
                {
                    marker = "PublishPlan";
                    LogIt($"Info: {marker}");

                    // Todo: Add publish plan code here
                }
                marker = "End";

                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Project={projectFullPath} Model={modelName} Marker={marker} Err={ex.Message}";
                Alert(explanation);
                return(false);
            }
        } // RunModel
Esempio n. 9
0
        static void Main(string[] args)
        {
            // Open project
            string[] warnings;
            try
            {
                Console.WriteLine("Start");
                // We'll assume our DLLs have been placed at the same location as this EXE
                string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                Console.WriteLine("Read Command Line Settings");
                if (args.Length == 0)
                {
                    throw new Exception("Project Path And File Must Be Specified In First Command Argument");
                }

                // set parameters
                string projectPathAndFile  = args[0];
                bool   runRiskAnalysis     = false;
                bool   saveModelAfterRun   = false;
                bool   publishPlanAfterRun = false;
                string modelName           = "Model";
                string publishName         = "";

                // set project file
                if (args.Length >= 2)
                {
                    runRiskAnalysis = Convert.ToBoolean(args[1]);
                }
                if (args.Length >= 3)
                {
                    saveModelAfterRun = Convert.ToBoolean(args[2]);
                }
                if (args.Length >= 4)
                {
                    publishPlanAfterRun = Convert.ToBoolean(args[3]);
                }
                if (args.Length >= 5)
                {
                    modelName = args[4];
                }
                if (args.Length >= 6)
                {
                    publishName = args[5];
                }

                // If File Not Exist, Throw Exeption
                if (File.Exists(projectPathAndFile) == false)
                {
                    throw new Exception("Project Not Found : " + projectPathAndFile);
                }

                Console.WriteLine("Project Name = " + projectPathAndFile);

                // Open project file.
                Console.WriteLine($"Loading Model=[{modelName}]");
                _simioProject = SimioProjectFactory.LoadProject(projectPathAndFile, out warnings);

                // Run schedule and save for existing events.
                var model = _simioProject.Models[modelName];
                if (model == null)
                {
                    Console.WriteLine("Model Not Found In Project");
                }
                else
                {
                    if (model.Plan == null)
                    {
                        throw new ApplicationException($"Model's Plan is null. Do you have the correct Simio licensing?");
                    }

                    // Start Plan
                    Console.WriteLine("Starting Plan");
                    RunPlanOptions options = new RunPlanOptions();
                    options.AllowDesignErrors = false;

                    model.Plan.RunPlan(options);
                    if (runRiskAnalysis)
                    {
                        Console.WriteLine("Plan Finished...Starting Analyze Risk");
                        model.Plan.RunRiskAnalysis();
                    }

                    if (saveModelAfterRun)
                    {
                        Console.WriteLine("Save Project After Schedule Run");
                        SimioProjectFactory.SaveProject(_simioProject, projectPathAndFile, out warnings);
                    }

                    // Publish the plan to portal after Run.
                    // This (of course) requires the URL of your Portal, plus an access token (PAT) for security.
                    if (publishPlanAfterRun)
                    {
                        Console.WriteLine("Info: PublishPlan");
                        string url = "https://test.internal.SimioPortal.com/";
                        string pat = "eyJ1IjoiZGFuX2hvdWNrQGhvdG1haWwuY29tIiwidCI6Ik9zeEp1bmtqdnBPaHcxR2RlUk9INjBSTUcyVm51SFpXSFBQbmpYMVNHREo3cjFkT0pMWVZhQXpFeHdzM0RvVWlIWU41Tjd4YUFhZndVNmNFekVuN1FBPT0ifQ ==";
                        var    pub = DoPublish(url, projectPathAndFile, pat, modelName, publishName, "Scheduling Discrete Part Production");
                        pub.Wait();
                    }


                    Console.WriteLine("End");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("RunError=" + ex.Message);
            }
        }
        /// <summary>
        /// Set the extensionpath, load a project, then load the model, and run a plan for that model.
        /// </summary>
        /// <param name="extensionsPath">For DLL search. E.g. AppDomain.CurrentDomain.BaseDirectory</param>
        /// <param name="projectPathAndFile"></param>
        /// <param name="arguments">Comma delimited string of arguments</param>
        /// <param name="runRiskAnalysis"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunProjectPlan(string extensionsPath, string projectFullPath, List <RequestArgument> argList, out string explanation)
        {
            explanation = "";
            string marker = "Begin";

            string[] warnings;

            try
            {
                // Set an extensions path to where we can locate User Extensions, etc.
                if (string.IsNullOrEmpty(extensionsPath))
                {
                    extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                    LogIt($"Info: No ExtensionsPath supplied. Defaulting to={extensionsPath}");
                }

                marker = $"Setting Extensions Path to={extensionsPath}";
                LogIt($"Info: {marker}");

                string saveAs = GetArgumentAsString(argList, "saveAs", "", out explanation);
                if (saveAs != null && !Directory.Exists(saveAs))
                {
                    explanation = $"SaveAs path={saveAs} does not exist.";
                    return(false);
                }

                string modelName       = GetArgumentAsString(argList, "model", "model", out explanation);
                bool?  runRiskAnalysis = GetArgumentAsBoolean(argList, "riskAnalysis", false, out explanation);
                if (runRiskAnalysis == null)
                {
                    explanation = $"{explanation}";
                    return(false);
                }
                bool?publishPlan = GetArgumentAsBoolean(argList, "publishPlan", false, out explanation);

                // Load the Project
                ISimioProject project = null;
                try
                {
                    //Cursor.Current = Cursors.WaitCursor;
                    SimioProjectFactory.SetExtensionsPath(extensionsPath);

                    project = LoadProject(extensionsPath, projectFullPath, out explanation);
                    if (project == null)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    explanation = $"Cannot load from {projectFullPath}. Err={ex.Message}";
                    return(false);
                }
                finally
                {
                    //Cursor.Current = Cursors.Default;
                }

                // Load the Model
                IModel model = LoadModel(project, modelName, out explanation);
                if (model == null)
                {
                    return(false);
                }



                // Test to see if we can 'cheat'
                IPlan plan = (IPlan)model;
                plan.RunPlan(new RunPlanOptions()
                {
                    AllowDesignErrors = true
                });

                // Check for Plan
                if (model.Plan == null)
                {
                    explanation = $"Model={model.Name} has no Plan (you may not have a license for one)";
                    return(false);
                }

                // Start Plan
                marker = "Starting Plan (model.Plan.RunPlan)";
                LogIt($"Info: {marker}");
                model.Plan.RunPlan(new RunPlanOptions()
                {
                    AllowDesignErrors = true
                });

                IPlan plan2 = (IPlan)model;
                plan2.RunPlan(new RunPlanOptions()
                {
                    AllowDesignErrors = true
                });

                if (runRiskAnalysis.Value)
                {
                    marker = "Plan Finished...Starting Analyze Risk (model.Plan.RunRiskAnalysis)";
                    LogIt($"Info: {marker}");
                    model.Plan.RunRiskAnalysis();
                }

                if (saveAs != null)
                {
                    marker = $"Saving Project to={saveAs}";
                    LogIt($"Info: {marker}");
                    SimioProjectFactory.SaveProject(project, saveAs, out warnings);
                }

                if (publishPlan.Value)
                {
                    marker = "PublishPlan";
                    LogIt($"Info: {marker}");

                    // Todo: Add publish plan code here
                }
                marker = "End";

                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Project={projectFullPath} Marker={marker} Err={ex.Message}";
                Alert(explanation);
                return(false);
            }
        } // RunModel
Esempio n. 11
0
        private void CalcularButton_Click(object sender, EventArgs e)
        {
            SimioProjectFactory.SetExtensionsPath(System.AppDomain.CurrentDomain.BaseDirectory);
            string[] warnings;
            try
            {
                string path = "Modelo1_G1.spfx";
                if (File.Exists(path) == false)
                {
                    throw new ApplicationException($"Proyecto no encontrado:{path}");
                }

                ISimioProject _simioProject = SimioAPI.SimioProjectFactory.LoadProject(path, out warnings);
                IModel        model         = _simioProject.Models[1];

                //var jsonObj = JsonConvert.DeserializeObject<List<aeropuerto>>(sb.ToString());
                //foreach (var obj in jsonObj)
                //{
                //    model.Facility.IntelligentObjects.CreateObject("Combiner", new FacilityLocation(obj.posicion_x, obj.posicion_z, obj.posicion_y));

                //}

                model.Facility.IntelligentObjects.CreateObject("Source", new FacilityLocation(0, 0, 0));
                var objetoA = model.Facility.IntelligentObjects["Source1"];
                objetoA.ObjectName = "Personas";
                objetoA.Properties["EntityType"].Value       = "ModelEntity1";
                objetoA.Properties["InterarrivalTime"].Value = "Random.Poisson(5)";

                INodeObject nodo       = ((IFixedObject)model.Facility.IntelligentObjects["Personas"]).Nodes[0];
                var         nombreNodo = nodo.Properties["OutboundLinkRule"];
                nombreNodo.Value = "By Link Weight";
                //[64] = {EnteredAddOnProcess: }
                var exitedProcess = nodo.Properties["EnteredAddOnProcess"];
                exitedProcess.Value = "Process1";

                model.Facility.IntelligentObjects.CreateObject("Source", new FacilityLocation(-20, 0, 0));
                var objetoB = model.Facility.IntelligentObjects["Source1"];
                objetoB.ObjectName = "Aviones";
                objetoB.Properties["EntityType"].Value       = "ModelEntity2";
                objetoB.Properties["InterarrivalTime"].Value = "Random.Poisson(0.1)";

                foreach (DataRow fila in dt.Rows)
                {
                    //model.Facility.IntelligentObjects.CreateObject("Combiner", new FacilityLocation(Convert.ToDouble(fila[2]), Convert.ToDouble(fila[3]), Convert.ToDouble(fila[4])));
                    model.Facility.IntelligentObjects.CreateObject("Combiner", new FacilityLocation(Convert.ToDouble(fila[2]), Convert.ToDouble(fila[4]), Convert.ToDouble(fila[3])));

                    var objeto = model.Facility.IntelligentObjects["Combiner1"];
                    objeto.ObjectName = "aeropuerto_" + Convert.ToString(fila[0]);

                    model.Facility.IntelligentObjects.CreateObject("Sink", new FacilityLocation((Convert.ToDouble(fila[2]) - 5), Convert.ToDouble(fila[4]), Convert.ToDouble(fila[3])));

                    var entradaAeropuerto = model.Facility.IntelligentObjects["Sink1"];
                    entradaAeropuerto.ObjectName = "AuxAeropuerto_" + Convert.ToString(fila[0]);

                    String      vari           = "aeropuerto_" + Convert.ToString(fila[0]);
                    INodeObject nodo2          = ((IFixedObject)model.Facility.IntelligentObjects[vari]).Nodes[1];
                    var         exitedProcess2 = nodo2.Properties["EnteredAddOnProcess"];
                    exitedProcess2.Value = "Write_Bitacora";

                    //FailureType = 61
                    objeto.Properties[61].Value = Convert.ToString(fila[5]);
                    //CountBetweenFailures = 63
                    objeto.Properties[63].Value = Convert.ToString(fila[6]);
                    //TimeToRepair = 65
                    objeto.Properties[65].Value = Convert.ToString((Convert.ToDouble(fila[7]) / 60));
                    //InitialCapacity = 16
                    objeto.Properties[16].Value = Convert.ToString(fila[8]);
                    //ProcessingTime = 39
                    objeto.Properties[39].Value = Convert.ToString(fila[10]);
                    //BatchQuantity = 27
                    objeto.Properties[27].Value = "100";
                    //MemberTransferInTime
                    objeto.Properties["MemberTransferInTime"].Value = Convert.ToString(fila[9]);;


                    String      combi         = "aeropuerto_" + Convert.ToString(fila[0]);
                    INodeObject a             = ((IFixedObject)model.Facility.IntelligentObjects["Personas"]).Nodes[0];
                    INodeObject b             = ((IFixedObject)model.Facility.IntelligentObjects[combi]).Nodes[1];
                    var         arista        = model.Facility.IntelligentObjects.CreateLink("Path", a, b, null);
                    var         tipoSeleccion = arista.Properties["SelectionWeight"];
                    //Math.If( ModelEntity.destino == 1, 1, 0 )
                    tipoSeleccion.Value = "Math.If( ModelEntity.a_origen == " + Convert.ToString(fila[0]) + ", 1, 0 )";

                    String      combi2 = "aeropuerto_" + Convert.ToString(fila[0]);
                    INodeObject a2     = ((IFixedObject)model.Facility.IntelligentObjects["Aviones"]).Nodes[0];
                    INodeObject b2     = ((IFixedObject)model.Facility.IntelligentObjects[combi]).Nodes[0];
                    model.Facility.IntelligentObjects.CreateLink("Path", a2, b2, null);
                }

                //var objeto2 = model.Facility.IntelligentObjects["aeropuerto_1"];
                //objeto2.ObjectName = "nuevo";


                /**************Esto es para los Path**************/
                //Destino posicion 0
                //Origen posicion 1

                foreach (DataRow fila in dt2.Rows)
                {
                    String aux1 = "aeropuerto_" + fila[0];
                    String aux2 = "aeropuerto_" + fila[1];
                    String aux3 = "AuxAeropuerto_" + fila[0];

                    //Aeropuerto Origen -> Salida
                    INodeObject a = ((IFixedObject)model.Facility.IntelligentObjects[aux2]).Nodes[2];
                    INodeObject b = ((IFixedObject)model.Facility.IntelligentObjects[aux3]).Nodes[0];
                    model.Facility.IntelligentObjects.CreateLink("Path", a, b, null);
                }

                //*************** Esto es para los experimentos **********/
                //IExperiment experimento = model.Experiments.Create("Experimento");

                ////configurando el experimento
                //IRunSetup setup = experimento.RunSetup;
                //setup.StartingTime = new DateTime(2018, 10, 1);
                //setup.WarmupPeriod = TimeSpan.FromHours(0);
                //setup.EndingTime = experimento.RunSetup.StartingTime + TimeSpan.FromDays(1);
                //experimento.ConfidenceLevel = ExperimentConfidenceLevelType.Point95;
                //experimento.LowerPercentile = 25;
                //experimento.UpperPercentile = 75;
                ////configuracion variable de control

                ////configurando los responses
                ////a estos hay que asignarles un valor en el escenario
                //IExperimentResponse response1 = experimento.Responses.Create("CantidadAviones");
                //response1.Expression = "avion.cantidad"; //valor de ejemplo
                //IExperimentResponse response2 = experimento.Responses.Create("CantidadPersonasTranportadas");
                //response2.Expression = "personas.cantidad"; //valor de ejemplo

                ////creando un escenario
                //IScenario escenario1 = experimento.Scenarios.Create("escenario1");
                //IScenario escenario2 = experimento.Scenarios.Create("escenario2");
                //IScenario escenario3 = experimento.Scenarios.Create("escenario3");

                //escenario creados
                //TODO cambiar la variable de control por escenario
                //como se hace? el metodo de controls de cada escenario solo tiene un get
                //que solo devueleve el valor del control pero no para asignarselo

                SimioProjectFactory.SaveProject(_simioProject, path, out warnings);
                MessageBox.Show("Carga realizada");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Esempio n. 12
0
        static void Main(string[] args)
        {
            // Open project
            string[] warnings;
            try
            {
                string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                Logit($"Info: Starting. Default ExtensionsPath={extensionsPath}.");
                SimioProjectFactory.SetExtensionsPath(extensionsPath);
                Logit($"Info: ExtensionsPath Set successfully.");

                Logit("Read Command Line Settings");
                if (args.Length == 0)
                {
                    throw new Exception("Project Path And File Must Be Specified In First Command Argument");
                }

                // set parameters
                string projectPathAndFile = args[0];
                bool   saveModelAfterRun  = false;
                string modelName          = "Model";
                string experimentName     = "";

                if (!File.Exists(projectPathAndFile))
                {
                    throw new ApplicationException($"Cannot find SimioProject file at={projectPathAndFile}");
                }

                if (args.Length >= 2)
                {
                    saveModelAfterRun = Convert.ToBoolean(args[1]);
                }
                if (args.Length >= 3)
                {
                    modelName = args[2];
                }
                if (args.Length >= 4)
                {
                    experimentName = args[3];
                }

                // If File Not Exist, Throw Exeption
                if (File.Exists(projectPathAndFile) == false)
                {
                    throw new Exception("Project Not Found : " + projectPathAndFile);
                }

                string projectFolder = Path.GetDirectoryName(projectPathAndFile);

                Logit($"Project Name={projectPathAndFile} Model={modelName} Experiment={experimentName} SaveAfterRun={saveModelAfterRun}");

                // Test if experiment can be done.
                string simpleTestProjectFullpath = Path.Combine(projectFolder, "LicenseExperimentTest.spfx");
                if (File.Exists(simpleTestProjectFullpath))
                {
                    Logit($"Info: Testing license with Project=[{simpleTestProjectFullpath}]");

                    try
                    {
                        Logit($"Info: Loading License Project=[{simpleTestProjectFullpath}]");
                        ISimioProject simioProject = SimioProjectFactory.LoadProject(simpleTestProjectFullpath, out warnings);

                        if (!SimEngineHelpers.RunModelExperiment(simioProject, "", "Model", "Experiment1",
                                                                 out string explanation))
                        {
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ApplicationException($"LicenseTest: Cannot Run Simple Experiment. Err={ex.Message}");
                    }
                }

                // Open project file.
                Logit($"Loading Project=[{projectPathAndFile}]");
                _simioProject = SimioProjectFactory.LoadProject(projectPathAndFile, out warnings);

                // Run schedule and save for existing events.
                var model = _simioProject.Models[modelName];
                if (model == null)
                {
                    throw new ApplicationException($"Model={modelName} Not Found In Project={projectPathAndFile}");
                }
                else
                {
                    if (model.Experiments == null)
                    {
                        throw new ApplicationException($"Model's Experiments collection is null.");
                    }

                    // Start Experiment
                    Logit("Starting Experiment");

                    string savePathAndFile = "";
                    if (saveModelAfterRun)
                    {
                        savePathAndFile = projectPathAndFile;
                    }

                    if (!SimEngineHelpers.RunModelExperiment(extensionsPath, projectPathAndFile, savePathAndFile, modelName, experimentName,
                                                             out string explanation))
                    {
                        throw new ApplicationException(explanation);
                    }
                    else
                    {
                        Logit($"Info: Model={modelName} Experiment={experimentName} performed the actions successfully. Check the logs for more information.");
                    }


                    if (saveModelAfterRun)
                    {
                        Logit("Save Project After Experiment Run");
                        SimioProjectFactory.SaveProject(_simioProject, projectPathAndFile, out warnings);
                    }

                    Logit("End");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Logit($"RunError={ex.Message}");
            }
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            // Open project
            string[] warnings;
            try
            {
                Console.WriteLine("Start");
                string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory;
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                Console.WriteLine("Read Command Line Settings");
                if (args.Length == 0)
                {
                    throw new Exception("Project Path And File Must Be Specified In First Command Argument");
                }

                // set parameters
                string projectPathAndFile = args[0];
                bool   saveModelAfterRun  = false;
                string modelName          = "Model";
                string experimentName     = "";

                if (!File.Exists(projectPathAndFile))
                {
                    throw new ApplicationException($"Cannot find SimioProject file at={projectPathAndFile}");
                }

                if (args.Length >= 2)
                {
                    saveModelAfterRun = Convert.ToBoolean(args[1]);
                }
                if (args.Length >= 3)
                {
                    modelName = args[2];
                }
                if (args.Length >= 4)
                {
                    experimentName = args[3];
                }

                // If File Not Exist, Throw Exeption
                if (File.Exists(projectPathAndFile) == false)
                {
                    throw new Exception("Project Not Found : " + projectPathAndFile);
                }

                Console.WriteLine("Project Name = " + projectPathAndFile);

                // Open project file.
                Console.WriteLine($"Loading Model=[{modelName}]");
                _simioProject = SimioProjectFactory.LoadProject(projectPathAndFile, out warnings);

                // Run schedule and save for existing events.
                var model = _simioProject.Models[modelName];
                if (model == null)
                {
                    Console.WriteLine("Model Not Found In Project");
                }
                else
                {
                    if (model.Experiments == null)
                    {
                        throw new ApplicationException($"Model's Experiments collection is null.");
                    }

                    // Start Experiment
                    Console.WriteLine("Starting Experiment");
                    string projectPath = "";

                    if (!HeadlessHelpers.RunExperiment(extensionsPath, projectPath, modelName, experimentName, saveModelAfterRun,
                                                       out string explanation))
                    {
                        throw new ApplicationException(explanation);
                    }
                    else
                    {
                        Console.WriteLine($"Info: Model={modelName} Experiment={experimentName} performed the actions successfully. Check the logs for more information.");
                    }


                    if (saveModelAfterRun)
                    {
                        Console.WriteLine("Save Project After Experiment Run");
                        SimioProjectFactory.SaveProject(_simioProject, projectPathAndFile, out warnings);
                    }

                    Console.WriteLine("End");
                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("RunError=" + ex.Message);
            }
        }
Esempio n. 14
0
        } // RunModel

        /// <summary>
        /// Run an experiment and save.
        /// </summary>
        /// <param name="extensionsPath"></param>
        /// <param name="projectPath"></param>
        /// <param name="modelName"></param>
        /// <param name="experimentName"></param>
        /// <param name="explanation"></param>
        /// <returns></returns>
        public static bool RunProjectExperiment(string extensionsPath, string projectPath, List <RequestArgument> argList,
                                                out string explanation)
        {
            explanation = "";

            string marker = "Begin";

            try
            {
                if (!File.Exists(projectPath))
                {
                    explanation = $"No such Project={projectPath}";
                    return(false);
                }

                string projectFolder   = Path.GetDirectoryName(projectPath);
                string projectFilename = Path.GetFileName(projectPath);


                string saveFolder = GetArgumentAsString(argList, "saveFolder", projectFolder, out explanation);
                if (saveFolder != null && !Directory.Exists(saveFolder))
                {
                    explanation = $"SaveFolder={saveFolder} does not exist.";
                    return(false);
                }

                string saveFilename = GetArgumentAsString(argList, "saveFilename", projectFilename, out explanation);
                string savePath     = Path.Combine(saveFolder, saveFilename);

                string modelName      = GetArgumentAsString(argList, "model", "model", out explanation);
                string experimentName = GetArgumentAsString(argList, "experiment", "experiment1", out explanation);


                marker = $"Setting ExtensionsPath={extensionsPath}";
                SimioProjectFactory.SetExtensionsPath(extensionsPath);

                marker = $"Loading Project from={projectPath}";
                string[] warnings;

                var _simioProject = SimioProjectFactory.LoadProject(projectPath, out warnings);
                if (warnings.Length > 0)
                {
                    StringBuilder sbLog = new StringBuilder();
                    foreach (var warning in warnings)
                    {
                        sbLog.Append($" [{warning}]");
                    }

                    explanation = $"Cannot load Project={projectPath} as there were {warnings.Length} warnings={sbLog}";
                    return(false);
                }

                marker = $"Access the model={modelName} and Experiment={experimentName}";
                var model = _simioProject.Models[modelName];
                if (model == null)
                {
                    explanation = "Model Not Found In Project";
                    return(false);
                }
                else
                {
                    if (model.Experiments == null)
                    {
                        explanation = $"Model's Experiments collection is null.";
                        return(false);
                    }

                    // Start Experiment
                    Console.WriteLine("Starting Experiment");

                    if (!SimEngineHelpers.RunModelExperiment(extensionsPath, projectPath, savePath,
                                                             modelName, experimentName,
                                                             out explanation))
                    {
                        return(false);
                    }
                    else
                    {
                        marker = $"Info: Model={modelName} Experiment={experimentName} performed the actions successfully. Check the logs for more information.";
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                explanation = $"Marker={marker} Project={projectPath}. Err={ex.Message}";
                return(false);
            }
        }