Common Modeling Pitfalls

Coordinator
May 1, 2008 at 2:06 AM
Edited May 1, 2008 at 2:17 AM
(Originally posted by jpe Oct 2 2007)

There are a few common pitfalls that one can stumble upon when writing model programs. You have the full C# language to use but there are a few things one has to keep in mind that are specific to model programs. Here are just a few I have come across.

  • Sets, Maps, Bags and Sequences are immutable. I.e. to add something to a set you have to write Set<string> mySet = Set<string>.EmptySet; mySet = mySet.Add("stuff");

  • When creating objects to use in model programs they should inherit from the LabeledInstance<T> class like public class DiningPhilosopher : LabeledInstance<DiningPhilosopher>

  • Your class definition that inherits from LabeledInstance<T> should contain a public override void Initialize() {} method, and all the default assignments to class fields should go there.

  • When creating your objects that inherit from LabeledInstance<T> from inside an action body, make sure you use the .Create() method (and not the new T() constructor). Thus to create an object of type DiningPhilosopher defined above, you should write something like the following: DiningPhilosopher p = DiningPhilosopher.Create();
Coordinator
May 1, 2008 at 2:14 AM
Edited May 1, 2008 at 2:17 AM
(originally posted by jpe Oct 7 2007)

I think that the "No parameter generator" error message should contain more specific information about where it went wrong. It seems that the problem is related to initalisation of the parameter domains. Model program raises an exception before actually making it to the initialisation action where the parameter domains are populated. Thus, a good heuristic would be to initialise all parameter domains to EmptySet upon declaration.
Coordinator
May 1, 2008 at 2:16 AM
(originally posted by jpe Nov 19 2007)

I think that the "No parameter generator" error message should contain more specific information about where it went wrong. The following error is really difficult to debug.

• mpv /r:Models.dll MyModel.Contract.Create
Unexpected error occurred.

Unhandled Exception: System.InvalidOperationException: No parameter generator at NModel.Execution.LibraryModelProgram.ActionParameterDomain(IState state, Symbol actionSymbol, Int32 parameterIndex) in NModel\Execution\ModelProgramProvider\LibraryModelProgram.cs:line 1093
at NModel.Execution.LibraryModelProgram.AllParameterCombinations(IState state, Symbol actionSymbol) in NModel\Execution\ModelProgramProvider\LibraryModelProgram.cs:line 1278
at NModel.Execution.LibraryModelProgram.<GetActions>d__18.MoveNext() in NModel\Execution\ModelProgramProvider\LibraryModelProgram.cs:line 1237
at NModel.Visualization.ExploredTransitions.ShowReachable(Term node) in NModel.Visualization\ModelProgramGraphView.cs:line 589
at NModel.Visualization.ModelProgramGraphView.SetModelProgram(ModelProgram mo
delProgram1) in NModel.Visualization\ModelProgramGraphView.cs:line 280
at NModel.Visualization.CommandLineViewer.RunWithCommandLineArguments(String[
] args) in NModel.Visualization\ModelProgramViewerCommandLine.cs:line 191
at NModel.Tools.MPV.Main(String[] args) in MPV\Program.cs:line 50