Unable to AddObjective after Clear due to name collision

19 views
Skip to first unread message

Jessica Wong

unread,
Jan 15, 2020, 1:09:56 PM1/15/20
to OPTANO Modeling

If I build a model, then call the Clear() function, that is supposed to clear any existing Objectives. However when I try to AddObjective again it fails with:
 System.InvalidOperationException : The Model already contains an Objective with the name <objective name>. Please choose a different name.

I can confirm that Clear removes the objective since I can see ObjectiveCount = 0 before the AddObjective. If I change the objective name (by adding a timestamp), then AddObjective works.

Is this a bug?

OPTANO Team

unread,
Jan 15, 2020, 1:53:33 PM1/15/20
to OPTANO Modeling
Hi,

Indeed. Sounds broken.
I'll run a few tests on that and will get back to you asap.

Best,
jp

OPTANO Team

unread,
Jan 15, 2020, 2:31:41 PM1/15/20
to OPTANO Modeling
Hi!

We have reproduced the issue and created a fix.
It will be reviewed shortly and then published to nuget.



As of now, you might use a workaround. just add some unique element to the objectives name, such as
 model.AddObjective(new Objective(x), string.Format( "Test {0}", DateTime.Now.GetHashCode().ToString()));



or replace the model with
model = new Model();


 Thanks for sending in this issue!

Best,
jp

OPTANO Team

unread,
Jan 16, 2020, 5:46:24 AM1/16/20
to OPTANO Modeling
Please find the fixed version online on nuget.org

Best,
jp

Jessica Wong

unread,
Jan 16, 2020, 9:52:34 AM1/16/20
to OPTANO Modeling
What is the version number that includes this fix?
Reply all
Reply to author
Forward
0 new messages