|
<< Click to Display Table of Contents >> Maps |
![]() ![]()
|
A map is a Gekko variable which is basically a kind of mini-databank, just with a different dot syntax, using #m.x (series x inside map #m), instead of b:x (series x inside databank b). Both maps and databanks implement the IBank C# interface, to make sure that they both work similarly (besides the syntax difference).
At the moment, the map capabilities are a bit basic, but maps are handy for returning multiple variables from a function call (like returning a mini-databank).
All Gekko variable types implement the IVariable interface. This makes sure that all the variables implement for instance an Add() or Multiply() method to handle the + and * operators, etc. What is special about the Map variable type is that it also implements the IBank interface, which the Databank class also implements.
The IBank interface looks like this:
public interface IBank { IVariable GetIVariable(string variable); void AddIVariable(string name, IVariable x); void AddIVariable(string name, IVariable x, bool isSimpleName); bool ContainsIVariable(string name); void RemoveIVariable(string name); EBankType BankType(); string Message(); } |
So the interface deals with getting a variable (like b:x in a databank or #m.x in a map), setting a variable (like b:y = x; in a databank or #m.y = x; in a map), checking if a variable exists (ContainsIVariable()), remove a variable (RemoveIVariable()), and BankType() returns info on whether the object is a databank or a map (enumeration EBankType). The Message() method just returns "databank 'b'" (for instance) or "map", respectively, for message printing.
Using the IBank interface for both databanks and maps may seem like a bit of an overkill, since the interface does not cover that much code. But it ensures that the internals of getting/setting a variable in a databank or in a map works in a consistent way, now and in the future.