Beispiel #1
0
        public void AddVariableWithOverwrite(bool freqAddToName, EFreq frequency, TimeSeries ts, bool variableNameCheck)
        {
            if (this.protect)
            {
                Program.ProtectError("You cannot add a timeseries to a non-editable databank, see OPEN<edit> or UNLOCK");
            }
            string variable = ts.variableName;

            if (variableNameCheck && !G.IsSimpleToken(variable))  //also checks for null and "" and '¤'
            {
                G.Writeln2("*** ERROR in databank: the name '" + variable + "' is not a simple variable name");
                throw new GekkoException();
            }
            if (freqAddToName)
            {
                variable = Program.AddFreqAtEndOfVariableName(variable);
            }
            else
            {
                variable = Program.AddFreqAtEndOfVariableName(variable, frequency);
            }
            if (this.storage.ContainsKey(variable))
            {
                this.storage.Remove(variable);
            }
            this.storage.Add(variable, ts);
            ts.parentDatabank = this;
            this.isDirty      = true;
        }
Beispiel #2
0
 private GekkoTime(EFreq freq2, int super2, int sub2, bool check)
 {
     //The check argument is not actually used, just can call the method with 'false'.
     //This method is only used for looping and adding internally, not for creating
     //a fresh new GekkoTime from command input. Hence the method is private.
     freq  = freq2;
     super = super2;
     sub   = sub2;
 }
Beispiel #3
0
        public TimeSeries GetVariable(EFreq eFreq, string variable)
        {
            if (eFreq != EFreq.Annual)
            {
                variable = Program.AddFreqAtEndOfVariableName(variable, eFreq);                         //we do this IF here because it is speed critical code. Else a new string object will be created.
            }
            TimeSeries x = null; this.storage.TryGetValue(variable, out x);

            return(x);
        }
Beispiel #4
0
 public GekkoTimeIteratorBackwards(GekkoTime startDate, GekkoTime endDate)
 {
     _StartDate = startDate;
     _EndDate   = endDate;
     if (startDate.freq != endDate.freq)
     {
         G.Writeln2("*** ERROR: Internal error, mismatch of frequencies");
         throw new GekkoException();
     }
     _freq = startDate.freq;
 }
Beispiel #5
0
 public void RemoveVariable(EFreq eFreq, string variable)
 {
     if (this.protect)
     {
         Program.ProtectError("You cannot remove a timeseries in a non-editable databank, see OPEN<edit> or UNLOCK");
     }
     variable = Program.AddFreqAtEndOfVariableName(variable, eFreq);
     if (ContainsVariable(false, variable))  //do not add freq at the end (has just been added)
     {
         this.storage.Remove(variable);
     }
     this.isDirty = true;
     return;
 }
Beispiel #6
0
 //Note: using "new GekkoTime()" without arguments is not intended to be used, even
 //      though it is valid to do. Such a struct cannot have its fields changed anyway, so
 //      it will be unusable.
 public GekkoTime(EFreq freq2, int super2, int sub2)
 {
     freq  = freq2;
     super = super2;
     sub   = sub2;
     //Sanity checks to follow
     //Problem is that TIME 2010m13 2012m0 can probably parse. If not, the check below is not necessary.
     if (sub < 1)
     {
         G.Writeln2("*** ERROR: subperiod < 1");
         throw new GekkoException();
     }
     if (freq == EFreq.Annual)
     {
         if (sub > 1)
         {
             G.Writeln2("*** ERROR: freq 'a' cannot have subperiod > 1");
             throw new GekkoException();
         }
     }
     else if (freq == EFreq.Quarterly)
     {
         if (sub > 4)
         {
             G.Writeln2("*** ERROR: freq 'q' cannot have subperiod > 4");
             throw new GekkoException();
         }
     }
     else if (freq == EFreq.Monthly)
     {
         if (sub > 12)
         {
             G.Writeln2("*** ERROR: freq 'm' cannot have subperiod > 12");
             throw new GekkoException();
         }
     }
     else if (freq == EFreq.Undated)
     {
         if (sub > 1)
         {
             G.Writeln2("*** ERROR: freq 'u' cannot have subperiod > 1");
             throw new GekkoException();
         }
     }
 }
Beispiel #7
0
        public static int Observations(GekkoTime t1, GekkoTime t2)
        {
            //BEWARE: Can return a negative number!
            if (t1.freq != t2.freq)
            {
                G.Writeln2("*** ERROR: Freq mismatch");
                throw new GekkoException();
            }
            EFreq efreq      = t1.freq;
            int   subPeriods = 1;

            if (efreq == EFreq.Annual)
            {
                //fast return
                return(t2.super - t1.super + 1);  //Subpers are ignored. It is tacitly assumed that the subperiods are = 1 here, else this is nonsense
            }
            else if (efreq == EFreq.Quarterly)
            {
                subPeriods = 4;
            }
            else if (efreq == EFreq.Monthly)
            {
                subPeriods = 12;
            }
            else if (efreq == EFreq.Undated)
            {
                subPeriods = 1;                               //ttfreq
            }
            else
            {
                G.Writeln2("*** ERROR: Error regarding frequency");
                throw new GekkoException();
            }

            int obs = subPeriods * (t2.super - t1.super) + t2.sub - t1.sub + 1;

            if (obs < 0)
            {
                //This should not normally be possible, maybe with PRT<2010 2009> or the like?
            }
            return(obs);
        }
 /// <summary>
 /// Constructor that creates a new TimeSeries object with a particular frequency and variable name.
 /// </summary>
 /// <param name="frequency">The frequency of the timeseries</param>
 /// <param name="variableName">The variable name of the timeseries</param>
 public TimeSeries(EFreq frequency, string variableName)
 {
     this.freqEnum     = frequency;
     this.frequency    = G.GetFreq(frequency);
     this.variableName = variableName;
 }
Beispiel #9
0
        public void Write(string path)
        {
            G.Writeln();
            //G.writeln("------------------------------------------------------");
            Type type = typeof(Options);           // Get type pointer

            FieldInfo[] fields = type.GetFields(); // Obtain all fields

            List <string> lines = new List <string>();

            foreach (var field in fields) // Loop through fields
            {
                string line     = "";
                string name     = field.Name; // Get string name
                string longName = "Program_options_" + name;
                string path2    = path.Replace(".", "_");
                if (!longName.Contains(path2))
                {
                    continue;
                }
                line += "option ";
                name  = name.Replace("_", " ");
                object temp = field.GetValue(this); // Get value
                if (temp is int)                    // See if it is an integer.
                {
                    int value = (int)temp;
                    line += name + " = " + value + ";";
                }
                else if (temp is string) // See if it is a string.
                {
                    string value = temp as string;
                    if (value == "")
                    {
                        value = "[empty]";
                    }
                    line += name + " = " + value + ";";
                }
                else if (temp is bool) // See if it is a string.
                {
                    bool   value = (bool)temp;
                    string yesno = "no";
                    if (value)
                    {
                        yesno = "yes";
                    }
                    line += name + " = " + yesno + ";";
                }
                else if (temp is double) // See if it is a string.
                {
                    double value = (double)temp;
                    string s     = value.ToString();
                    s     = Program.MaybeAddPointAndZero(s);
                    line += name + " = " + s + ";";
                }
                else if (temp is EFreq) // See if it is a freq.
                {
                    EFreq  value = (EFreq)temp;
                    string s     = "???";
                    if (value == EFreq.Annual)
                    {
                        s = "a";
                    }
                    else if (value == EFreq.Quarterly)
                    {
                        s = "q";
                    }
                    else if (value == EFreq.Monthly)
                    {
                        s = "m";
                    }
                    else if (value == EFreq.Undated)
                    {
                        s = "u";
                    }
                    line += name + " = " + s + ";";
                }
                else
                {
                    line += name + " = ???;";
                }
                if (G.equal(Program.options.interface_mode, "data") && line.StartsWith("option solve ", StringComparison.OrdinalIgnoreCase))
                {
                    //do nothing
                }
                else
                {
                    lines.Add(line);
                }
            }

            lines.Sort(StringComparer.InvariantCulture);
            foreach (string s in lines)
            {
                if (s.Contains("option r exe path"))
                {
                    continue;                                  //renamed to folder
                }
                G.Writeln(s);
            }
            G.Writeln();
            if (G.equal(Program.options.interface_mode, "data"))
            {
                G.Writeln("+++ NOTE: option solve... are not listed in data-mode");
            }

            if (path == "Program.options")
            {
                StringBuilder sb = new StringBuilder();
                if (true)
                {
                    sb.AppendLine();
                    sb.AppendLine("Some tips on finding and setting options in Gekko.");
                    sb.AppendLine();
                    sb.AppendLine("It is planned to provide a graphical representation of the");
                    sb.AppendLine("different Gekko options. Until this is implemented, some tips");
                    sb.AppendLine("may be helpful.");
                    sb.AppendLine();
                    sb.AppendLine("Option explanations are in the helpfile: 'HELP option'.");
                    sb.AppendLine();
                    sb.AppendLine("If 'OPTION interface suggestions = option' is set (this is");
                    sb.AppendLine("default), a small suggestions-window will pop up when you press");
                    sb.AppendLine("[space] while writing an option command. This window will");
                    sb.AppendLine("show the different possibilities, and you may select the preferred");
                    sb.AppendLine("sub-option and press [enter] or double-click your choice. This way,");
                    sb.AppendLine("you can see what options are possible at any location in the");
                    sb.AppendLine("option tree.");
                    sb.AppendLine();
                    sb.AppendLine("To see what options are set, you may use 'OPTION ?', or you can also");
                    sb.AppendLine("have only the first level of sub-options shown, by means of for instance");
                    sb.AppendLine("'OPTION solve ?'. If you need to change a particular option, you may");
                    sb.AppendLine("copy-paste it from the listing and change the value. If unsure about");
                    sb.AppendLine("legal values for a particular option, try removing the current value");
                    sb.AppendLine("and press [space]. For instance, consider 'OPTION solve method = gauss'.");
                    sb.AppendLine("Try removing 'gauss' and press [space]. This will pop up a small window");
                    sb.AppendLine("showing the legal choices.");
                }
                Program.LinkContainer lc = new Program.LinkContainer(sb.ToString());
                Globals.linkContainer.Add(lc.counter, lc);
                G.Write("Advice on finding and setting options ");
                G.WriteLink("here", "outputtab:" + lc.counter); G.Writeln(".");
            }
        }