Skip to content

Commit 973de33

Browse files
guillaume-vantroeyendanielgodard
authored andcommitted
Merged in feature/refactor_name_api (pull request #2)
getName and setNAme overridings Approved-by: Daniel Godard <daniel.godard@decisionbrain.com>
2 parents 7366a6e + 9007dff commit 973de33

File tree

11 files changed

+16
-109
lines changed

11 files changed

+16
-109
lines changed

src/examples/scala/com/decisionbrain/cplex/cp/SchedCalendar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ object SchedCalendar {
9292
val results = for ((rd, index) <- houses.zipWithIndex) yield makeHouse(index, rd)
9393

9494
endVars = results.map(_._1)
95-
allTaskVars = results.flatMap(_._2).map(v => (v.getName().getOrElse(""), v)).toMap
95+
allTaskVars = results.flatMap(_._2).map(v => (v.getName.getOrElse(""), v)).toMap
9696
joeTaskVars = results.flatMap(_._3)
9797
jimTaskVars = results.flatMap(_._4)
9898

src/examples/scala/com/decisionbrain/cplex/mp/DietMultiObj.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ object DietMultiObj {
182182

183183
// Print the objective value(s).
184184

185-
val costName = cost.getName()
185+
val costName = cost.getName
186186
val costValue = model.getValue(cost.getNumExpr())
187-
val varietyName = variety.getName()
187+
val varietyName = variety.getName
188188
val varietyValue = model.getValue(variety.getNumExpr())
189189
println(s"Solution value 0 ($costName) = $costValue")
190190
println(s"Solution value 1 ($varietyName) = $varietyValue")

src/main/scala/com/decisionbrain/cplex/Addable.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ trait Addable {
1616
*
1717
* @return the name of the object
1818
*/
19-
def getName: Option[String]
19+
def getName: Option[String] = Option(getIloAddable().getName)
2020

2121
/**
2222
* Set the name of the model addable object.
2323
*
2424
* @param name is the name of the object
2525
*/
26-
def setName(name: String)
26+
def setName(name: String): Addable = {
27+
getIloAddable().setName(name)
28+
this
29+
}
2730

2831
/**
2932
* Returns the CPLEX addable object.

src/main/scala/com/decisionbrain/cplex/Constraint.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ class Constraint(c: IloConstraint)(implicit modeler: Modeler) extends IntExpr(c)
2323
*/
2424
def getIloConstraint(): IloConstraint = c
2525

26-
/**
27-
* Returns the name of model addable object.
28-
*
29-
* @return the name of the object
30-
*/
31-
override def getName(): Option[String] = Option(c.getName())
32-
33-
/**
34-
* Set the name of the model addable object.
35-
*
36-
* @param name is the name of the object
37-
*/
38-
override def setName(name: String): Unit = c.setName(name)
39-
4026
/**
4127
* Returns the CPLEX addable object.
4228
*

src/main/scala/com/decisionbrain/cplex/IntVar.scala

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ class IntVar(v: IloIntVar)(implicit modeler: Modeler) extends IntExpr(v) with Ad
3131
*/
3232
def getType(): IloNumVarType = v.getType
3333

34-
/**
35-
* Return the name of the numeric variable
36-
* @return the name
37-
*/
38-
def getName(): Option[String] = Option(v.getName())
39-
40-
/**
41-
* Set the name of the numeric variable.
42-
*
43-
* @param name is the name of the numeric variable
44-
*/
45-
def setName(name: String) = v.setName(name)
46-
4734
/**
4835
* Return the upper bound of the numeric variable.
4936
*
@@ -121,7 +108,7 @@ class IntVar(v: IloIntVar)(implicit modeler: Modeler) extends IntExpr(v) with Ad
121108
*/
122109
override def toString() : String = {
123110
val strBuilder = new StringBuilder()
124-
if (getName().isDefined) strBuilder.append(getName().get)
111+
if (getName.isDefined) strBuilder.append(getName.get)
125112
strBuilder.append("[")
126113
val vmin = getMin()
127114
val vmax = getMax()

src/main/scala/com/decisionbrain/cplex/NumVar.scala

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ class NumVar(v: IloNumVar)(implicit modeler: Modeler) extends NumExpr(v) with Ad
2323
*/
2424
def getType(): IloNumVarType = v.getType
2525

26-
/**
27-
* Return the name of the numeric variable
28-
* @return the name
29-
*/
30-
def getName(): Option[String] = Option(v.getName())
31-
32-
/**
33-
* Set the name of the numeric variable.
34-
*
35-
* @param name is the name of the numeric variable
36-
*/
37-
def setName(name: String) = v.setName(name)
38-
3926
/**
4027
* Return the upper bound of the numeric variable.
4128
*
@@ -85,7 +72,7 @@ class NumVar(v: IloNumVar)(implicit modeler: Modeler) extends NumExpr(v) with Ad
8572
*/
8673
override def toString() : String = {
8774
val strBuilder = new StringBuilder()
88-
if (getName().isDefined) strBuilder.append(getName().get)
75+
if (getName.isDefined) strBuilder.append(getName.get)
8976
strBuilder.append("[")
9077
val vmin = getLB()
9178
val vmax = getUB()

src/main/scala/com/decisionbrain/cplex/Objective.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ import ilog.concert._
1616
*/
1717
class Objective(o: IloObjective)(implicit modeler: Modeler) extends Addable {
1818

19-
/**
20-
* Returns the name of model addable object.
21-
*
22-
* @return the name of the object
23-
*/
24-
override def getName(): Option[String] = Option(o.getName())
25-
26-
/**
27-
* Set the name of the model addable object.
28-
*
29-
* @param name is the name of the object
30-
*/
31-
override def setName(name: String): Unit = o.setName(name)
32-
3319
/**
3420
* Returns the CPLEX addable object
3521
*

src/main/scala/com/decisionbrain/cplex/cp/CumulFunctionExpr.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,6 @@ class CumulFunctionExpr(val expr: IloCumulFunctionExpr)(implicit model: CpModel)
122122
*/
123123
override def toString: String = expr.toString()
124124

125-
/**
126-
* Returns the name of model addable object.
127-
*
128-
* @return the name of the object
129-
*/
130-
override def getName: Option[String] = Option(expr.getName())
131-
132-
/**
133-
* Set the name of the model addable object.
134-
*
135-
* @param name is the name of the object
136-
*/
137-
override def setName(name: String): Unit = expr.setName(name)
138-
139125
/**
140126
* Returns the CPLEX addable object.
141127
*

src/main/scala/com/decisionbrain/cplex/cp/IntervalSequenceVar.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,6 @@ class IntervalSequenceVar(val expr: IloIntervalSequenceVar)(implicit model: CpMo
6161
*/
6262
override def toString: String = expr.toString()
6363

64-
/**
65-
* Returns the name of model addable object.
66-
*
67-
* @return the name of the object
68-
*/
69-
override def getName: Option[String] = Option(expr.getName())
70-
71-
/**
72-
* Set the name of the model addable object.
73-
*
74-
* @param name is the name of the object
75-
*/
76-
override def setName(name: String): Unit = expr.setName(name)
77-
7864
/**
7965
* Returns the CPLEX addable object.
8066
*

src/main/scala/com/decisionbrain/cplex/cp/IntervalVar.scala

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ class IntervalVar(v: IloIntervalVar)(implicit model: CpModel) extends Addable {
3434
*/
3535
def getIloIntervalVar(): IloIntervalVar = v
3636

37-
38-
/**
39-
* Return the name of the numeric variable
40-
* @return the name
41-
*/
42-
def getName(): Option[String] = Option(v.getName())
43-
44-
/**
45-
* Set the name of the numeric variable.
46-
*
47-
* @param name is the name of the numeric variable
48-
*/
49-
def setName(name: String) = v.setName(name)
50-
5137
/**
5238
* Returns the CPLEX numeric variable
5339
*

0 commit comments

Comments
 (0)