-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
remove assumption of integer objective, fixes #23 #24
base: development
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ public class PruneNodeEvent<T extends ModelInterface, U extends AbstractColumn<T | |
/** Bound on this node **/ | ||
public final double nodeBound; | ||
/** Best integer solution discovered so far **/ | ||
public final int bestIntegerSolution; | ||
public final double bestIntegerSolution; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this variable should probably be renamed, as it is no longer an integer solution. I would change it to: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, the term integer solution is somewhat vague anyhow as the integrality could refer to both the objective value as well as the integrality of the solution itself. I will change this. |
||
|
||
/** | ||
* Creates a new PruneNodeEvent | ||
|
@@ -46,7 +46,7 @@ public class PruneNodeEvent<T extends ModelInterface, U extends AbstractColumn<T | |
* @param nodeBound Bound on the node | ||
* @param bestIntegerSolution Best integer solution discovered thus far | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. description needs update |
||
*/ | ||
public PruneNodeEvent(Object source, BAPNode<T, U> node, double nodeBound, int bestIntegerSolution) | ||
public PruneNodeEvent(Object source, BAPNode<T, U> node, double nodeBound, double bestIntegerSolution) | ||
{ | ||
super(source); | ||
this.node = node; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ public class StartEvent | |
* Best available integer solution at the start of the Branch-and-Price or Column generation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. descr needs update |
||
* procedure | ||
**/ | ||
public final int objectiveIncumbentSolution; | ||
public final double objectiveIncumbentSolution; | ||
|
||
/** | ||
* Creates a new StartEvent | ||
|
@@ -43,7 +43,7 @@ public class StartEvent | |
* @param objectiveIncumbentSolution Best available integer solution at the start of the | ||
* Branch-and-Price or Column generation procedure | ||
*/ | ||
public StartEvent(Object source, String instanceName, int objectiveIncumbentSolution) | ||
public StartEvent(Object source, String instanceName, double objectiveIncumbentSolution) | ||
{ | ||
super(source); | ||
this.instanceName = instanceName; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ public class ColGen<T extends ModelInterface, U extends AbstractColumn<T, V>, | |
* is a maximization problem, the Colgen procedure is terminated if | ||
* {@code floor(boundOnMasterObjective) <= cutoffValue}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. desr needs update |
||
**/ | ||
protected int cutoffValue; | ||
protected double cutoffValue; | ||
/** | ||
* Bound on the best attainable objective value from the master problem. Assuming that the | ||
* master is a minimization problem, the Colgen procedure is terminated if | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. descr needs update |
||
|
@@ -114,7 +114,7 @@ public class ColGen<T extends ModelInterface, U extends AbstractColumn<T, V>, | |
public ColGen( | ||
T dataModel, AbstractMaster<T, U, V, ? extends MasterData<T, U, V, ?>> master, List<V> pricingProblems, | ||
List<Class<? extends AbstractPricingProblemSolver<T, U, V>>> solvers, List<U> initSolution, | ||
int cutoffValue, double boundOnMasterObjective) | ||
double cutoffValue, double boundOnMasterObjective) | ||
{ | ||
this.dataModel = dataModel; | ||
this.master = master; | ||
|
@@ -161,7 +161,7 @@ public ColGen( | |
public ColGen( | ||
T dataModel, AbstractMaster<T, U, V, ? extends MasterData<T, U, V, ?>> master, V pricingProblem, | ||
List<Class<? extends AbstractPricingProblemSolver<T, U, V>>> solvers, List<U> initSolution, | ||
int cutoffValue, double boundOnMasterObjective) | ||
double cutoffValue, double boundOnMasterObjective) | ||
{ | ||
this( | ||
dataModel, master, Collections.singletonList(pricingProblem), solvers, initSolution, | ||
|
@@ -188,7 +188,7 @@ public ColGen( | |
public ColGen( | ||
T dataModel, AbstractMaster<T, U, V, ? extends MasterData<T, U, V, ?>> master, List<V> pricingProblems, | ||
List<Class<? extends AbstractPricingProblemSolver<T, U, V>>> solvers, | ||
PricingProblemManager<T, U, V> pricingProblemManager, List<U> initSolution, int cutoffValue, | ||
PricingProblemManager<T, U, V> pricingProblemManager, List<U> initSolution, double cutoffValue, | ||
double boundOnMasterObjective) | ||
{ | ||
this.dataModel = dataModel; | ||
|
@@ -519,10 +519,17 @@ public List<AbstractInequality> getCuts() | |
*/ | ||
protected boolean boundOnMasterExceedsCutoffValue() | ||
{ | ||
if (optimizationSenseMaster == OptimizationSense.MINIMIZE) | ||
return Math.ceil(boundOnMasterObjective - config.PRECISION) >= cutoffValue; | ||
else | ||
return Math.floor(boundOnMasterObjective + config.PRECISION) <= cutoffValue; | ||
if (config.INTEGER_OBJECTIVE) { | ||
if (optimizationSenseMaster == OptimizationSense.MINIMIZE) | ||
return Math.ceil(boundOnMasterObjective - config.PRECISION) >= cutoffValue; | ||
else | ||
return Math.floor(boundOnMasterObjective + config.PRECISION) <= cutoffValue; | ||
} else { | ||
if (optimizationSenseMaster == OptimizationSense.MINIMIZE) | ||
return boundOnMasterObjective >= cutoffValue; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check: how to handle precision correctly. |
||
else | ||
return boundOnMasterObjective <= cutoffValue; | ||
} | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ public class SimpleDebugger<T extends ModelInterface, U extends AbstractColumn<T | |
/** Name of the instance being solved **/ | ||
protected String instanceName; | ||
/** Best integer solution obtained thus far **/ | ||
protected int bestIntegerSolution; | ||
protected double bestIntegerSolution; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best to rename this to: objectiveIncumbentSolution |
||
|
||
/** | ||
* Creates a debugger for Column Generation instances | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ protected Configuration() | |
CUTSENABLED = true; | ||
EXPORT_MODEL = false; | ||
EXPORT_MASTER_DIR = "./output/masterLP/"; | ||
INTEGER_OBJECTIVE = true; | ||
|
||
// Cut handling | ||
QUICK_RETURN_AFTER_CUTS_FOUND = true; | ||
|
@@ -70,6 +71,8 @@ protected Configuration(Properties properties) | |
? Boolean.valueOf(properties.getProperty("EXPORT_MODEL")) : false); | ||
EXPORT_MASTER_DIR = (properties.containsKey("EXPORT_MODEL_DIR") | ||
? properties.getProperty("EXPORT_MODEL_DIR") : "./output/masterLP/"); | ||
INTEGER_OBJECTIVE = (properties.containsKey("INTEGER_OBJECTIVE") | ||
? Boolean.valueOf(properties.getProperty("INTEGER_OBJECTIVE")): true); | ||
|
||
// Cut handling | ||
QUICK_RETURN_AFTER_CUTS_FOUND = (properties.containsKey("QUICK_RETURN_AFTER_CUTS_FOUND") | ||
|
@@ -122,6 +125,8 @@ public static void readFromFile(Properties properties) | |
public final boolean EXPORT_MODEL; | ||
/** Define export directory for master models. Default: ./output/masterLP/ **/ | ||
public final String EXPORT_MASTER_DIR; | ||
/** Defines if an integer solution has an integer objective. Default = true */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to be a bit more verbose here: |
||
public final boolean INTEGER_OBJECTIVE; | ||
|
||
/* | ||
* Cut handling | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,14 +92,14 @@ public void testBAPFrameworkThroughTSP() | |
if (inputStream == null) | ||
Assert.fail("Cannot find problem instance!"); | ||
TSP tsp = new TSP(inputStream); | ||
int solution = this.solveTSPInstance(tsp); | ||
double solution = this.solveTSPInstance(tsp); | ||
System.out.println("Solution for : " + instance + " is: " + solution); | ||
Assert.assertEquals(solution, instances.get(instance).intValue()); | ||
Assert.assertEquals(solution, instances.get(instance).intValue(), 0.000001); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Config.PRECISION |
||
inputStream.close(); | ||
} | ||
} | ||
|
||
private int solveTSPInstance(TSP tsp) | ||
private double solveTSPInstance(TSP tsp) | ||
{ | ||
if (tsp.N % 2 == 1) | ||
throw new RuntimeException( | ||
|
@@ -146,7 +146,7 @@ private int solveTSPInstance(TSP tsp) | |
bap.runBranchAndPrice(System.currentTimeMillis() + 8000000L); | ||
|
||
// Get the solution | ||
int solution = -1; | ||
double solution = -1; | ||
if (bap.hasSolution()) { | ||
assert (bap.isOptimal()); | ||
solution = bap.getObjective(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this bit is tricky. It doesn't take the precision into account. I need to read up on this topic to decide what is the best comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also not entirely sure what to do here either. However, allowing to deviate by the precision would mean that this would be allowed recursively if the nodes are pruned. Hence, the final precision could turn out significantly worse than the given precision. That was my reason for not taking it into account here.