Esempio n. 1
0
 public double GetVal(GekkoTime t)
 {
     //Asking a general timeless GetVal() from a timeseries (and not getting a val with a particular GekkoTime) is used in GENR, PRT etc. in an internal GekkoTime loop. Hence the use of Globals.globalGekkoTimeIterator_DO_NOT_ALTER.
     if (t.IsNull())
     {
         G.Writeln2("*** ERROR: You are trying to extract a single value from timeseries: " + this.ts.variableName + ".");
         G.Writeln("           Did you forget []-brackets to pick out an observation, for instance x[2020]?");
         throw new GekkoException();
     }
     return(this.ts.GetData(t.Add(this.offset)));
 }
Esempio n. 2
0
            public static IVariable Add(ScalarVal x, MetaTimeSeries ats, GekkoTime t)
            {
                //no need to implement swap
                if (t.IsNull())
                {
                    throw new GekkoException();
                }
                TimeSeries ts   = ats.ts;
                double     val1 = x.val;
                double     val2 = ts.GetData(t.Add(ats.offset));

                return(new ScalarVal(val1 + val2));
            }
Esempio n. 3
0
        public double GetVal(GekkoTime t)
        {
            //Asking a general timeless GetVal() from a timeseries (and not getting a val with a particular GekkoTime) is used in GENR, PRT etc. in an internal GekkoTime loop. Hence the use of Globals.globalGekkoTimeIterator_DO_NOT_ALTER.
            if (t.IsNull())
            {
                G.Writeln2("*** ERROR: You are trying to extract a single value from timeseries: " + this.ts.variableName + ".");
                G.Writeln("           Did you forget []-brackets to pick out an observation, for instance x[2020]?");
                throw new GekkoException();
            }
            double d = this.ts.GetData(t.Add(this.offset));

            if (Program.options.series_array_ignoremissing && !this.ts.IsTimeless() && this.ts.variableName != null && this.ts.variableName.Contains(Globals.symbolTurtle))
            {
                if (double.IsNaN(d))
                {
                    d = 0d;
                }
            }
            return(d);
        }
Esempio n. 4
0
        public static void C1(P p)
        {
            GekkoTime t = Globals.tNull;

            p.SetText(@"¤9");
            O.List o9 = new O.List();
            o9.name      = O.GetString((new ScalarString("i")));
            o9.listItems = new List <string>();
            o9.p         = p;
            o9.listItems = new List <string>();
            o9.listItems.AddRange(O.GetList((new ScalarString("a"))));

            o9.listItems.AddRange(O.GetList((new ScalarString("b"))));

            o9.Exe();



            p.SetText(@"¤10");
            O.Genr    o10  = new O.Genr();
            IVariable ts11 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("y"))), 1, O.ECreatePossibilities.Can);
            IVariable ts13 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("x"))), 1);

            o10.t1 = Globals.globalPeriodStart;
            o10.t2 = Globals.globalPeriodEnd;

            o10.lhs = null;
            o10.p   = p;
            foreach (GekkoTime t2 in new GekkoTimeIterator(o10.t1, o10.t2))
            {
                t = t2;
                double[]  storage16 = new double[2];
                int       counter17 = 0;
                GekkoTime t3        = t2;

                foreach (IVariable s1177 in new O.GekkoListIterator(O.GetScalarFromCache(ref list12, "#i", false, false)))
                {
                    t = t3;
                    double[] storage14 = new double[0 - (-1) + 1];
                    int      counter15 = 0;
                    foreach (GekkoTime t4 in new GekkoTimeIterator(t3.Add(-1), t3.Add(0)))
                    {
                        t = t4;
                        storage14[counter15] = O.GetVal(O.Indexer(t, ts13, false, s1177), t);
                        counter15++;
                        t = t3;
                    }
                    storage16[counter17] = O.GetVal(O.HandleSummations("dif", storage14), t);
                    counter17++;
                }
                double data = O.GetVal(O.HandleSummations("sum", storage16), t);
                if (o10.lhs == null)
                {
                    o10.lhs = O.GetTimeSeries(ts11);
                }
                o10.lhs.SetData(t, data);
            }
            t        = Globals.tNull;
            o10.meta = @"ser y = sum(#i, dif(x[#i]))";
            o10.Exe();



            p.SetText(@"¤12");
            O.Prt o11 = new O.Prt();
            o11.prtType = "p";

            o11.t1 = Globals.globalPeriodStart;
            o11.t2 = Globals.globalPeriodEnd;

            o11.printCodes.Add(new OptString("n", O.GetString(new ScalarString("yes"))));



            {
                List <int>    bankNumbers = null;
                O.Prt.Element ope11       = new O.Prt.Element();
                ope11.label = O.SubstituteScalarsAndLists("x['a']", false);
                bankNumbers = O.Prt.GetBankNumbers(null, Program.GetElementPrintCodes(o11, ope11));
                foreach (int bankNumber in bankNumbers)
                {
                    IVariable ts18 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("x"))), bankNumber);
                    foreach (GekkoTime t2 in new GekkoTimeIterator(o11.t1.Add(-2), o11.t2))
                    {
                        t = t2;
                        O.GetVal777(O.Indexer(t, ts18, false, new ScalarString(@"a")), bankNumber, ope11, t);
                    }
                    t = Globals.tNull;
                }
                o11.prtElements.Add(ope11);
            }

            {
                List <int>    bankNumbers = null;
                O.Prt.Element ope11       = new O.Prt.Element();
                ope11.label = O.SubstituteScalarsAndLists("x['b']", false);
                bankNumbers = O.Prt.GetBankNumbers(null, Program.GetElementPrintCodes(o11, ope11));
                foreach (int bankNumber in bankNumbers)
                {
                    IVariable ts19 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("x"))), bankNumber);
                    foreach (GekkoTime t2 in new GekkoTimeIterator(o11.t1.Add(-2), o11.t2))
                    {
                        t = t2;
                        O.GetVal777(O.Indexer(t, ts19, false, new ScalarString(@"b")), bankNumber, ope11, t);
                    }
                    t = Globals.tNull;
                }
                o11.prtElements.Add(ope11);
            }

            {
                List <int>    bankNumbers = null;
                O.Prt.Element ope11       = new O.Prt.Element();
                ope11.label = O.SubstituteScalarsAndLists("x['a']+x['b']", false);
                bankNumbers = O.Prt.GetBankNumbers(null, Program.GetElementPrintCodes(o11, ope11));
                foreach (int bankNumber in bankNumbers)
                {
                    IVariable ts20 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("x"))), bankNumber);
                    foreach (GekkoTime t2 in new GekkoTimeIterator(o11.t1.Add(-2), o11.t2))
                    {
                        t = t2;
                        O.GetVal777(O.Add(O.Indexer(t, ts20, false, new ScalarString(@"a")), O.Indexer(t, ts20, false, new ScalarString(@"b")), t), bankNumber, ope11, t);
                    }
                    t = Globals.tNull;
                }
                o11.prtElements.Add(ope11);
            }

            {
                List <int>    bankNumbers = null;
                O.Prt.Element ope11       = new O.Prt.Element();
                ope11.label = O.SubstituteScalarsAndLists("y", false);
                bankNumbers = O.Prt.GetBankNumbers(null, Program.GetElementPrintCodes(o11, ope11));
                foreach (int bankNumber in bankNumbers)
                {
                    IVariable ts21 = O.GetTimeSeries(O.GetString(new ScalarString("[FIRST]")) + ":" + O.GetString((new ScalarString("y"))), bankNumber);
                    foreach (GekkoTime t2 in new GekkoTimeIterator(o11.t1.Add(-2), o11.t2))
                    {
                        t = t2;
                        O.GetVal777(ts21, bankNumber, ope11, t);
                    }
                    t = Globals.tNull;
                }
                o11.prtElements.Add(ope11);
            }


            o11.counter = 1;
            o11.Exe();
        }