Draw arrows to build models
You can do quite a bit of modeling just by drawing arrows between variables and modules without having to type in definitions explicitly. This works when the definition of the destination variable contains various kinds of list. For example, if variable Y
is defined as a simple list in square brackets and you draw an arrow from variable X
to Y
, it automatically adds X
into the list. You can also connect modules in a similar way by drawing arrows to and from Modules with TemplateInput and TemplateOutput Attributes.
Draw arrows to add variables into a definition
Suppose you draw an arrow from variable A
to B
. It automatically adds A
into the definition of B
when the definition of B
contains one of these kinds of list:
- A list in square brackets
For example:
B := Sum([X])
- If
A
isn't already in the list, it addsA
:
B := Sum([X, A])
- Or, if
A
, is already in the list, it removes it:
B := Sum([X])
If A is the only element in the list, it replaces it by expr, for example:
B := Sum([A])
- After redrawing the arrow from
A
, is already in the list, it removes it:
B := Sum([expr])
- If
A
is an Index
If B
is an Atom (single number or text value) or an Edit table, it offers to add A
as an Index of B
. This offers a convenient way to add an index dimension to a model. For example:
B := 100
- If
A
isn't already an index of the table, it offers to addA
as an index. If you accept, the result is:
B := Table(A)(...)
- Or, if
A
, is already an index, it offers to remove it (after warning you that it will lose data by removing a dimension). If you accept, it shows this result:
B := 100
For example:
B := ListofHandles([X])
- If
A
isn't already in the list, it addsA
:
B := ListofHandles([X, A])
- Or, if
A
, is already in the list, it removes it:
B := ListofHandles([X])
- Repeated parameters
If B
uses a function whose first parameter is qualified as Repeated (or "..."), it behaves like an explicit list in square brackets. For example,
Function ObjList(vars: ... Variable) B := Objlist(X) draw an arrow from A to B B := Objlist(X, A)
Note: "Repeated" means one or more elements. If you remove the last input by redrawing an arrow from A
to B
, it replaces it by "expr", which will not parse. If you want zero or more elements, you should qualify the parameter with Optional along with "...", for example:
Function ObjList(vars: ... Optional Variable)
Note: It automatically adds A
into the list in B
(or removes it if it's already there) if the defintion of B
contains one of the above constructs as its only element. If the Definition contains one of these constructs along with others, e.g.
B := [X] + 3
it does not do automatic insertion or removal. It simply adds A
as a possible input to B
, and leaves it to the modeler as to where to insert it into the definition.
Delete an arrow
If there is an arrow from variable A
to B
, you can delete it
- either by selecting the arrow and pressing the "delete" key,
- or by redrawing the arrow from
A
toB
.
If A
is already in the definition of B
, it asks if you want to remove A
from the Definition of B
. If so, it puts comment brackets around the origin variable {A}
, in the definition of B
, so you can see what was removed. Often, the resulting definition will have bad syntax, indicated by the node for B
becoming cross-hatched.
- Redraw a deleted arrow
- If you delete an input to
B
as above, and then redraw an arrow fromA
toB
, it restores the original definition by removing the comment brackets{A}
around the variable,A
.
Drawing arrows to Modules with TemplateInput and TemplateOutput attributes
You can even construct models by drawing arrows to and from modules, if the modules are set up as templates. A Template module should have one of its variables as the TemplateInput attribute of the module, and another variable as the TemplateOutput attribute. When you draw an arrow into a template module, it's the same as drawing an arrow into its template input variable. So, if the definition of the Template input variable contains a list [], ListofVariables, Edit table, or uses a function with a repeated parameter (as described above), when you draw an arrow into the module, it inserts the origin variable into the list. When you draw an arrow from a module with a TemplateOutput, it's as if you were drawing an arrow from the variable in the TemplateOutput.
It's often useful to create a template module and then make copies of it for particular instantiations. You can link them together by drawing arrows.
Enable comment auto-refresher