Skip to content

Commit

Permalink
unique name
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikPeters committed Feb 20, 2024
1 parent 48d6a32 commit 235d431
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export class Model {
addVar({ lb, ub, vtype, name } = {}) {
if (name === null || name === undefined) {
name = `Var${this.varCount++}`; // Assign an internal name if none provided
while (this.variables.has(name)) {
name = `Var${this.varCount++}`; // Ensure unique name
}
} else if (this.variables.has(name)) {
throw new Error(`Variable name '${name}' has already been used.`);
}
Expand Down

0 comments on commit 235d431

Please sign in to comment.