Skip to content

Commit

Permalink
Merge pull request #18 from blubin/develop
Browse files Browse the repository at this point in the history
Develop -> Master
  • Loading branch information
blubin committed Sep 10, 2019
2 parents 3a66760 + 8f685b7 commit 00d4b6f
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 124 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>edu.harvard.eecs</groupId>
<artifactId>jopt</artifactId>
<version>1.3.3</version>
<version>1.3.4</version>
<packaging>jar</packaging>

<name>Java Optimization</name>
Expand Down Expand Up @@ -110,7 +110,7 @@
<connection>scm:git:git://github.com/blubin/JOpt.git</connection>
<developerConnection>scm:git:git@github.com/blubin/JOpt.git</developerConnection>
<url>https://github.com/blubin/JOpt.git/tree/master/</url>
<tag>v1.3.3</tag>
<tag>v1.3.4</tag>
</scm>

<dependencies>
Expand All @@ -137,7 +137,7 @@
<dependency>
<groupId>cplex</groupId>
<artifactId>cplex</artifactId>
<version>12.8</version>
<version>12.9</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/edu/harvard/econcs/jopt/solver/IMIP.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public interface IMIP extends Serializable {
* of variables that distinguish different solutions in the context of the MIP. For example, in an auction,
* these variables could be the allocation variables.
*
* If you're interested in a more advanced structure of variables of interest,
* see {@link #setAdvancedVariablesOfInterest(Collection)}.
*
* @param variables The variables of interest. For SOLUTION_POOL_MODE = 3, only boolean variables are supported.
*/
default void setVariablesOfInterest(Collection<Variable> variables) {
Expand All @@ -109,9 +112,9 @@ default void setVariablesOfInterest(Collection<Variable> variables) {

/**
* Internally, the variables of interest are stored as a collection of collections, even when the user
* sets them as a single collection. A user may, however, set the variables of interest directly in this advanced
* sets them as a single collection. But a user may want to set the variables of interest directly in this advanced
* structure. This gives, without breaking the API of a simple collection of variables, the user the possibility
* to define sets of variables that all have to be equal in their sum to be considered a duplicate.
* to define <b>sets of variables that all have to be equal in their sum to be considered a duplicate.</b>
*
* @param variableSets The sets of variables of interest. For SOLUTION_POOL_MODE = 3, only boolean variables are
* supported.
Expand Down
17 changes: 1 addition & 16 deletions src/main/java/edu/harvard/econcs/jopt/solver/IMIPResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,12 @@
**/
public interface IMIPResult extends Serializable, ISolution {





/** Returns the dual of a constraint that was added with IMIP.add(constraint, constraintId) */
double getDual(Constraint constraint);



/** Dump the results out to std out, using the MIP to make it pretty **/
String toString(IMIP mip);

/** Get the Queue of pool solutions, if available **/
Queue<PoolSolution> getPoolSolutions();

/**
* @return the relative difference in the objective value compared to the relaxation of the problem
*/
double getRelativeGap();

/**
* @return the absolute difference in the objective value compared to the relaxation of the problem
*/
double getAbsoluteGap();
}
10 changes: 10 additions & 0 deletions src/main/java/edu/harvard/econcs/jopt/solver/ISolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ default int compareTo(ISolution o) {
return Double.compare(getObjectiveValue(), o.getObjectiveValue());
}

/**
* @return the relative difference in the objective value compared to the relaxation of the problem
*/
double getRelativeGap();

/**
* @return the absolute difference in the objective value compared to the relaxation of the problem
*/
double getAbsoluteGap();

/**
* To take advantage of the advanced structure of variables of interest, this method checks if for all collections
* collections of variables, the sum of these variables are equal.
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/edu/harvard/econcs/jopt/solver/SolveParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ public class SolveParam implements Serializable {
* Enables data check by CPLEX. 1 = activated, 2 = activated and show debug information in log
*/
public static final SolveParam DATACHECK = new SolveParam(24, Integer.class, "DataCheck");

/**
* Specifies type of optimality that CPLEX targets (optimal convex or first-order satisfaction) as it searches for a solution
* <ul>
* <li>0 (default): Automatic - let CPLEX decide</li>
* <li>1: Searches for a globally optimal solution to a convex model</li>
* <li>2: Searches for a solution that satisfies first-order optimality conditions, but is not necessarily globally optimal</li>
* <li>3: Searches for a globally optimal solution to a non-convex model; changes problem type to MIQP if necessary</li>
* </ul>
*/
public static final SolveParam OPTIMALITY_TARGET = new SolveParam(25, Integer.class, "OptimalityTarget");

/**
* Switches on or off linearization of the quadratic terms in the objective function of a quadratic program (QP) or of a mixed integer quadratic program (MIQP) during preprocessing.
* <ul>
* <li>-1 (default): Automatic - let CPLEX decide</li>
* <li>0: Off: CPLEX does not linearize quadratic terms in the objective function of QP, MIQP</li>
* <li>1: On: CPLEX linearizes quadratic terms in the objective function of QP, MIQP</li>
* </ul>
*/
public static final SolveParam QTOLIN = new SolveParam(26, Integer.class, "QToLin");

// Internal variables
// ///////////////////
/**
Expand Down Expand Up @@ -425,6 +447,10 @@ private Object readResolve() throws ObjectStreamException {
return SOLUTION_POOL_REPLACEMENT;
case 24:
return DATACHECK;
case 25:
return OPTIMALITY_TARGET;
case 26:
return QTOLIN;
case 101:
return PROBLEM_FILE;
case 102:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,21 @@ public class PoolSolution implements Serializable, ISolution {
private static final long serialVersionUID = -7265174347585717488L;
private double objectiveValue;
private final Map<String, Double> values;
private double relativeGap;
private double absoluteGap;
private double poolRelativeGap = -1;
private double poolAbsoluteGap = -1;

public PoolSolution(double objectiveValue, Map<String, Double> values) {
public PoolSolution(double objectiveValue, double bestObjectiveValue, Map<String, Double> values) {
this.objectiveValue = objectiveValue;
this.values = values;
this.absoluteGap = Math.abs(bestObjectiveValue - objectiveValue);
this.relativeGap = this.absoluteGap / (1e-10 + Math.abs(bestObjectiveValue));
}

public void setPoolGaps(double optimalObjectiveValue) {
this.poolAbsoluteGap = Math.abs(optimalObjectiveValue - objectiveValue);
this.poolRelativeGap = this.poolAbsoluteGap / (1e-10 + Math.abs(optimalObjectiveValue));
}

/*
Expand Down Expand Up @@ -135,10 +146,33 @@ public boolean equal(Object other) {
return this.objectiveValue == otherSolution.getObjectiveValue() && getValues().equals(otherSolution.getValues());
}

@Override
public double getRelativeGap() {
return relativeGap;
}

@Override
public double getAbsoluteGap() {
return absoluteGap;
}


@Override
public long getSolveTime() {
return 0;
}

/**
* @return The relative gap compared to the optimal feasible solution, if available. Else -1.
*/
public double getPoolRelativeGap() {
return poolRelativeGap;
}

/**
* @return The absolute gap compared to the optimal feasible solution, if available. Else -1.
*/
public double getPoolAbsoluteGap() {
return poolAbsoluteGap;
}
}
Loading

0 comments on commit 00d4b6f

Please sign in to comment.