예제 #1
0
        private void SetModel(XMileModel model)
        {
            cbGroups.Items.Clear();
            cbVariables.Items.Clear();
            var groups = model == null?_stateMachine.Models.GetGroups() : model.Groups;

            if (groups.Any())
            {
                cbGroups.Items.Add(All);
                cbGroups.Items.AddRange(groups.OrderBy(x => x.Name).ToArray());
                foreach (var group in groups)
                {
                    cbVariables.Items.AddRange(group.Entities.ToArray());
                }

                cbGroups.Enabled = true;
            }
            else
            {
                cbGroups.Enabled = false;
                if (model == null)
                {
                    cbVariables.Items.AddRange(_stateMachine.Models.GetVariables().ToArray());
                }
                else
                {
                    cbVariables.Items.AddRange(model.Variables.ToArray());
                }
            }

            btnSubModelProcess.Enabled = model != null;
        }
예제 #2
0
        public async Task ParseStocks(XContainer variables, XMileModel model)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            foreach (var stock in variables.Descendants(_ns + "stock"))
            {
                await Stock.CreateInstance(stock.FirstAttribute.Value,
                                           model,
                                           ParseEquation(stock),
                                           ParseInflows(stock),
                                           ParseOutflows(stock),
                                           ParseGraphicalFunction(stock),
                                           ParseRange(stock, "range"),
                                           ParseRange(stock, "scale"),
                                           ParseNonNegative(stock), ParseAccess(stock));
            }
        }
예제 #3
0
        public void ParseModules(XContainer variables, XMileModel model)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            foreach (var module in variables.Descendants(_ns + "module"))
            {
                Module.CreateInstance(model,
                                      module.FirstAttribute.Value,
                                      ParseConnects(module));
            }
        }
예제 #4
0
        public async Task ParseAuxiliaries(XContainer variables, XMileModel model)
        {
            if (variables == null)
            {
                throw new ArgumentNullException(nameof(variables));
            }

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            foreach (var auxiliary in variables.Descendants(_ns + "aux"))
            {
                await Auxiliary.CreateInstance(auxiliary.FirstAttribute.Value,
                                               model,
                                               ParseEquation(auxiliary),
                                               ParseGraphicalFunction(auxiliary),
                                               ParseRange(auxiliary, "range"),
                                               ParseRange(auxiliary, "scale"),
                                               ParseNonNegative(auxiliary), ParseAccess(auxiliary));
            }
        }
예제 #5
0
        public async Task <XMileModel> ParseModel(XElement xModel)
        {
            if (xModel == null)
            {
                throw new NullReferenceException(nameof(_xDoc.Root));
            }

            var variables = xModel.Descendants(_ns + "variables");

            var model = new XMileModel(xModel.FirstAttribute?.Value);

            foreach (var variable in variables)
            {
                await ParseStocks(variable, model);
                await ParseFlows(variable, model);
                await ParseAuxiliaries(variable, model);

                ParseGroups(variable, model);
                ParseModules(variable, model);
            }

            return(model);
        }
예제 #6
0
 /// <summary>
 ///     Add a model
 /// </summary>
 /// <param name="model"></param>
 public void Add(XMileModel model)
 {
     Models.Add(model);
 }