Example #1
0
        private void Run(double step, int time)
        {
            var equation = new StringBuilder(string.Empty);

            foreach (var item in items)
            {
                if (item is Stock)
                {
                    var stock = (Stock)item;
                    equation.Append(stock.Render() + '\n');
                }

                if (item is Flow)
                {
                    var flow = (Flow)item;
                    equation.Append(flow.Name + '=' + flow.Formula + '\n');
                }

                if (item is Coefficient)
                {
                    var coefficient = (Coefficient)item;

                    // equation.Append(coefficient.Render() + '\n');
                    equation.Append(coefficient.Name + '=' + coefficient.Formula + '\n');
                }
            }

            if (ValidateInputForEquationSolver(equation.ToString(), step.ToString(), time.ToString(), 1.ToString()))
            {
                values = Simulation.SolveEquation(equation.ToString(), step, time, 1);

                int cnt = 0;

                foreach (var item in values)
                {
                    foreach (var key in item.Keys)
                    {
                        if (cnt < item[key].Count)
                        {
                            cnt = item[key].Count;
                        }
                    }
                }

                var toRemove = new Dictionary <Dictionary <string, List <double> >, List <string> >();

                foreach (var item in values)
                {
                    var buf = new List <string>();

                    foreach (var kvp in item)
                    {
                        if (item[kvp.Key].Count < cnt)
                        {
                            buf.Add(kvp.Key);
                        }
                    }

                    if (buf.Count > 0)
                    {
                        toRemove.Add(item, buf);
                    }
                }

                foreach (var kvp in toRemove)
                {
                    foreach (var key in kvp.Value)
                    {
                        kvp.Key.Remove(key);
                    }
                }
            }
            else
            {
                MessageBox.Show(@"Incorrect input! Check the StartPoint, Step and Time input.");
            }
        }
        private void Run(double step, int time)
        {
            StringBuilder equation = new StringBuilder("");

            foreach (IDrawable var in _items)
            {
                if (var is Stock)
                {
                    Stock tStock;
                    tStock = (Stock)var;
                    equation.Append(tStock.Render() + '\n');
                }
                if (var is Flow)
                {
                    Flow tFlow;
                    tFlow = (Flow)var;
                    equation.Append(tFlow.Name + '=' + tFlow.Forumla + '\n');
                }
                if (var is Coefficient)
                {
                    Coefficient tCoefficient;
                    tCoefficient = (Coefficient)var;
                    //equation.Append(tCoefficient.Render() + '\n');
                    equation.Append(tCoefficient.Name + '=' + tCoefficient.Formula + '\n');
                }
            }

            if (ValidateInputForEquationSolver(equation.ToString(), step.ToString(), time.ToString(), 1.ToString()))
            {
                _values = Simulation.SolveEquation(equation.ToString(), step, time, 1);

                int cnt = 0;

                Dictionary <Dictionary <string, List <double> >, List <string> > toRemove = new Dictionary <Dictionary <string, List <double> >, List <string> >();

                foreach (Dictionary <string, List <double> > item in _values)
                {
                    foreach (string key in item.Keys)
                    {
                        if (cnt < item[key].Count)
                        {
                            cnt = item[key].Count;
                        }
                    }
                }

                foreach (Dictionary <string, List <double> > item in _values)
                {
                    List <string> buf = new List <string>();

                    foreach (KeyValuePair <string, List <double> > vls in item)
                    {
                        if (item[vls.Key].Count < cnt)
                        {
                            buf.Add(vls.Key);
                        }
                    }
                    if (buf.Count > 0)
                    {
                        toRemove.Add(item, buf);
                    }
                }

                foreach (KeyValuePair <Dictionary <string, List <double> >, List <string> > vls in toRemove)
                {
                    foreach (string key in vls.Value)
                    {
                        vls.Key.Remove(key);
                    }
                }
            }
            else
            {
                MessageBox.Show("Incorrect input! Check the StartPoint, Step and Time input.");
            }
        }