I got all the building blocks correct, but when it comes to merging all functions to a model, I typed in the codes as below and it keeps showing the same trackback about “costs”. I have no clue what’s going wrong here.
{moderator edit - solution code removed}
The way you are calling optimize
from model
is incorrect. Think about the meaning of the code you wrote: the value that optimize
gets for the number of iterations will always be 2000, regardless of what value gets passed into model
at the top level. What if the model
test case uses a value different than 2000? That will not end well, as we see in the trace you show.
If you are relatively new to python, it would be worth reading some of the tutorials on how functions work in python. Try googling “python named parameters” or “python keyword parameters” and have a look at how those work.