Skip to content

Commit 7366a6e

Browse files
committed
Move method 'add' from CpMode and MpModel to Modeler. Add method 'add' with a set of addable objects as parameter.
1 parent 80278be commit 7366a6e

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

RELEASENOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Add API for KPIs in CpModel: see example PlantLocation.scala
66
* Add methods quot in class CpModel for division and define operators '/' in class NumExpr
7+
* Move methods `add` from CpModel and MpModel to Modeler
78

89
## cplex-scala v1.5.2
910

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ println("Maven user: $MAVEN_USER")
3333

3434
task sourcesJar(type: Jar) {
3535
archiveClassifier = 'sources'
36-
from sourceSets.main.allJava
36+
from sourceSets.main.allSource
3737
}
3838

3939
task javadocJar(type: Jar) {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package com.decisionbrain.cplex
88

99
import com.decisionbrain.cplex.Modeler._
1010
import com.decisionbrain.cplex.cp.CpModel
11+
import com.decisionbrain.cplex.mp.MpModel
1112
import ilog.concert.{IloIntExpr, IloIntVar, IloModeler, IloNumExpr, IloNumVar}
1213

1314
import scala.reflect.ClassTag
@@ -834,6 +835,29 @@ abstract class Modeler {
834835
def ifThen(ct1: Constraint, ct2: Constraint): Constraint =
835836
Constraint(modeler.ifThen(ct1.getIloConstraint(), ct2.getIloConstraint()))(implicitly(this))
836837

838+
/**
839+
* Add an addable object in the model.
840+
*
841+
* @param a is the object to add to the model
842+
* @return the model
843+
*/
844+
def add(a: Addable, name: String=null): Modeler = {
845+
a.setName(name)
846+
modeler.add(a.getIloAddable())
847+
this
848+
}
849+
850+
/**
851+
* Add addable objects in the model.
852+
*
853+
* @param addables are the object to add to the model
854+
* @return the model
855+
*/
856+
def add(addables: Iterable[Addable]): Modeler = {
857+
modeler.add(addables.map(a => a.getIloAddable()).toArray)
858+
this
859+
}
860+
837861
/**
838862
* Creates and returns an objective object to minimize the expression <em>expr</em>.
839863
*

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,19 +2024,6 @@ case class CpModel(name: String=null) extends Modeler {
20242024
*/
20252025
def intSet(values: Array[Int]): IntSet = IntSet(cp.intSet(values))(implicitly(this))
20262026

2027-
2028-
/**
2029-
* Add an addable object in the model.
2030-
*
2031-
* @param a is the object to add to the model
2032-
* @return the model
2033-
*/
2034-
def add(a: Addable, name: String=null): CpModel = {
2035-
a.setName(name)
2036-
cp.add(a.getIloAddable())
2037-
this
2038-
}
2039-
20402027
/**
20412028
* Creates a minimization multi-criteria objective.
20422029
*

src/main/scala/com/decisionbrain/cplex/mp/MpModel.scala

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,17 +163,6 @@ case class MpModel(name: String=null) extends Modeler {
163163
*/
164164
def addRange(lb: Double, expr: NumExpr, ub: Double, name: String=""): MpModel = {
165165
add(range(lb, expr, ub, name))
166-
}
167-
168-
/**
169-
* Add an addable object in the model.
170-
*
171-
* @param a is the object to add to the model
172-
* @return the model
173-
*/
174-
def add(a: Addable, name: String=null): MpModel = {
175-
a.setName(name)
176-
cplex.add(a.getIloAddable())
177166
this
178167
}
179168

0 commit comments

Comments
 (0)