Beispiel #1
0
        public IVariable Indexer(IVariablesFilterRange indexRange, GekkoTime t)
        {
            IVariable iv1 = indexRange.first;
            IVariable iv2 = indexRange.last;

            if (iv1.Type() == EVariableType.String && iv2.Type() == EVariableType.String)
            {
                string        s1   = O.GetString(iv1);
                string        s2   = O.GetString(iv2);
                List <string> temp = Program.MatchRange(s1, s2, this.list, null);
                return(new MetaList(temp));
            }
            else
            {
                int i1 = O.GetInt(iv1);
                int i2 = O.GetInt(iv2);
                if (i1 < 1)
                {
                    G.Writeln2("*** ERROR: Starting index (" + i1 + ") cannot be < 1");
                    throw new GekkoException();
                }
                if (i1 > this.list.Count)
                {
                    G.Writeln2("*** ERROR: Ending index (" + i2 + ") cannot be > length (" + this.list.Count + ")");
                    throw new GekkoException();
                }
                if (i1 > i2)
                {
                    G.Writeln2("*** ERROR: Starting index (" + i1 + ") cannot be > than ending index (" + i2 + ")");
                    throw new GekkoException();
                }
                return(new MetaList(this.list.GetRange(i1 - 1, i2 - i1 + 1))); //GetRange() is a shallow copy, but that is okay since it contains immutable strings
            }
        }
Beispiel #2
0
        public IVariable SetData(IVariablesFilterRange indexRange1, IVariable x2, IVariable x3)
        {
            //Does not need to be so fast, so we use this trick
            IVariablesFilterRange range = new Gekko.IVariablesFilterRange(x2, x2);

            return(this.SetData(indexRange1, range, x3));
        }
Beispiel #3
0
        public IVariable Indexer(IVariablesFilterRange indexRange1, IVariablesFilterRange indexRange2, GekkoTime t)
        {
            int i1 = 1;
            int i2 = this.data.GetLength(0);
            int j1 = 1;
            int j2 = this.data.GetLength(1);

            if (indexRange1.first != null)
            {
                i1 = O.GetInt(indexRange1.first);
            }
            if (indexRange1.last != null)
            {
                i2 = O.GetInt(indexRange1.last);
            }
            if (indexRange2.first != null)
            {
                j1 = O.GetInt(indexRange2.first);
            }
            if (indexRange2.last != null)
            {
                j2 = O.GetInt(indexRange2.last);
            }
            if (i1 > i2)
            {
                G.Writeln2("*** ERROR: Range " + i1 + ".." + i2 + " is descending");
                throw new GekkoException();
            }
            if (j1 > j2)
            {
                G.Writeln2("*** ERROR: Range " + j1 + ".." + j2 + " is descending");
                throw new GekkoException();
            }
            try
            {
                Matrix m   = new Matrix(i2 - i1 + 1, j2 - j1 + 1);
                int    ii1 = i1 - 1;
                int    jj1 = j1 - 1;
                for (int i = i1 - 1; i <= i2 - 1; i++)
                {
                    for (int j = j1 - 1; j <= j2 - 1; j++)
                    {
                        m.data[i - ii1, j - jj1] = this.data[i, j];
                    }
                }
                return(m);
            }
            catch (System.IndexOutOfRangeException e)  // CS0168
            {
                G.Writeln("*** ERROR: Index out of range: [" + i1 + " .. " + i2 + ", " + j1 + " .. " + j2 + " ]");
                if (i1 == 0 || i2 == 0 || j1 == 0 || j2 == 0)
                {
                    G.Writeln("           Please note that indicies are 1-based");
                }
                throw new GekkoException();
            }
        }
Beispiel #4
0
        public IVariable Indexer(IVariablesFilterRange indexRange, GekkoTime t)
        {
            int d1 = this.data.GetLength(0);
            int d2 = this.data.GetLength(1);

            if (d2 == 1)
            {
                return(Indexer(indexRange, new ScalarVal(1d), t));
            }
            G.Writeln("*** ERROR: You are trying to use [ .. ] on a " + d1 + "x" + d2 + " matrix");
            G.Writeln("           This notation can only be used regarding nx1 matrices (column vectors)");
            throw new GekkoException();
        }
Beispiel #5
0
 public IVariable Indexer(IVariablesFilterRange indexRange, GekkoTime t)
 {
     if (this._string2 == Globals.indexerAloneCheatString)
     {
         //corresponds to empty index range like ['fx'..'fy'], different from #a['fx'..'fy']
         IVariable iv1 = indexRange.first;
         IVariable iv2 = indexRange.last;
         string    s1  = O.GetString(iv1);
         string    s2  = O.GetString(iv2);
         ExtractBankAndRestHelper h    = Program.ExtractBankAndRest(s1, EExtrackBankAndRest.GetDatabank);
         List <string>            temp = Program.MatchRangeInDatabank(h.name, s2, h.databank);
         return(new MetaList(temp));
     }
     else
     {
         G.Writeln2("*** ERROR: You cannot use []-index on string");
         throw new GekkoException();
     }
 }
Beispiel #6
0
        public IVariable Indexer(IVariable index, IVariablesFilterRange indexRange, GekkoTime t)
        {
            int i0 = O.GetInt(index);
            int j1 = 1;
            int j2 = this.data.GetLength(1);

            if (indexRange.first != null)
            {
                j1 = O.GetInt(indexRange.first);
            }
            if (indexRange.last != null)
            {
                j2 = O.GetInt(indexRange.last);
            }
            try
            {
                Matrix m = new Matrix(1, j2 - j1 + 1);

                int jj1 = j1 - 1;
                int i   = i0 - 1;

                for (int j = j1 - 1; j <= j2 - 1; j++)
                {
                    m.data[0, j - jj1] = this.data[i, j];
                }

                return(m);
            }
            catch (System.IndexOutOfRangeException e)  // CS0168
            {
                G.Writeln("*** ERROR: Index out of range: [" + i0 + ", " + j1 + " .. " + j2 + " ]");
                if (i0 == 0 || j1 == 0 || j2 == 0)
                {
                    G.Writeln("           Please note that indicies are 1-based");
                }
                throw new GekkoException();
            }
        }
Beispiel #7
0
 public IVariable Indexer(IVariablesFilterRange indexRange, IVariable index, GekkoTime t)
 {
     throw new GekkoException();
 }
Beispiel #8
0
 public IVariable Indexer(IVariablesFilterRange indexRange1, IVariablesFilterRange indexRange2, GekkoTime t)
 {
     G.Writeln2("*** ERROR: Cannot use []-indexer on VAL");
     throw new GekkoException();
 }
 public IVariable Indexer(IVariablesFilterRange indexRange, GekkoTime t)
 {
     G.Writeln2("*** ERROR: You are trying to use an [] index range on timeseries: " + this.ts.variableName + ".");
     throw new GekkoException();
 }
Beispiel #10
0
        public IVariable SetData(IVariablesFilterRange indexRange1, IVariablesFilterRange indexRange2, IVariable x3)
        {
            int i1 = 1;
            int i2 = this.data.GetLength(0);
            int j1 = 1;
            int j2 = this.data.GetLength(1);

            if (indexRange1.first != null)
            {
                i1 = O.GetInt(indexRange1.first);
            }
            if (indexRange1.last != null)
            {
                i2 = O.GetInt(indexRange1.last);
            }
            if (indexRange2.first != null)
            {
                j1 = O.GetInt(indexRange2.first);
            }
            if (indexRange2.last != null)
            {
                j2 = O.GetInt(indexRange2.last);
            }
            if (i1 > i2)
            {
                G.Writeln2("*** ERROR: Range " + i1 + ".." + i2 + " is descending");
                throw new GekkoException();
            }
            if (j1 > j2)
            {
                G.Writeln2("*** ERROR: Range " + j1 + ".." + j2 + " is descending");
                throw new GekkoException();
            }

            if (x3.Type() == EVariableType.Matrix)
            {
                Matrix m    = (Matrix)x3;
                int    dimI = i2 - i1 + 1;
                int    dimJ = j2 - j1 + 1;
                if (dimI != m.data.GetLength(0) || dimJ != m.data.GetLength(1))
                {
                    G.Writeln2("*** ERROR: Left-hand side selection is " + dimI + "x" + dimJ + ", but right-hand matrix is " + m.data.GetLength(0) + "x" + m.data.GetLength(1));
                    throw new GekkoException();
                }

                try
                {
                    int ii1 = i1 - 1;
                    int jj1 = j1 - 1;
                    for (int i = i1 - 1; i <= i2 - 1; i++)
                    {
                        for (int j = j1 - 1; j <= j2 - 1; j++)
                        {
                            this.data[i, j] = m.data[i - ii1, j - jj1];
                        }
                    }
                    return(this);
                }
                catch (System.IndexOutOfRangeException e)  // CS0168
                {
                    G.Writeln("*** ERROR: Left-side index out of range: [" + i1 + " .. " + i2 + ", " + j1 + " .. " + j2 + " ]");
                    if (i1 == 0 || i2 == 0 || j1 == 0 || j2 == 0)
                    {
                        G.Writeln("           Please note that indicies are 1-based");
                    }
                    throw new GekkoException();
                }
            }
            else if (x3.Type() == EVariableType.Val)
            {
                ScalarVal v = (ScalarVal)x3;
                try
                {
                    int ii1 = i1 - 1;
                    int jj1 = j1 - 1;
                    for (int i = i1 - 1; i <= i2 - 1; i++)
                    {
                        for (int j = j1 - 1; j <= j2 - 1; j++)
                        {
                            this.data[i, j] = v.val;
                        }
                    }
                    return(this);
                }
                catch (System.IndexOutOfRangeException e)  // CS0168
                {
                    G.Writeln("*** ERROR: Left-side index out of range: [" + i1 + " .. " + i2 + ", " + j1 + " .. " + j2 + " ]");
                    if (i1 == 0 || i2 == 0 || j1 == 0 || j2 == 0)
                    {
                        G.Writeln("           Please note that indicies are 1-based");
                    }
                    throw new GekkoException();
                }
            }
            else
            {
                G.Writeln2("*** ERROR: Expected right-hand side to be a matrix or a scalar");
                throw new GekkoException();
            }
        }