Skip to content
Snippets Groups Projects
Commit c2881ef7 authored by Daniel Khashabi's avatar Daniel Khashabi
Browse files

Merge branch 'daniel-coeff' into 'master'

adding a method to get the coefficient of the variable in the objective function.



See merge request !2
parents f4ca1eec 18fef5cb
No related branches found
No related tags found
1 merge request!2adding a method to get the coefficient of the variable in the objective function.
Pipeline #
...@@ -148,6 +148,11 @@ public class BeamSearch implements ILPSolver { ...@@ -148,6 +148,11 @@ public class BeamSearch implements ILPSolver {
return this.objectiveValue; return this.objectiveValue;
} }
@Override
public double objectiveCoeff(int index) {
return scores.get(index)[0];
}
public void reset() { public void reset() {
this.constraints = new ArrayList<ILPConstraint>(); this.constraints = new ArrayList<ILPConstraint>();
this.scores = new ArrayList<double[]>(); this.scores = new ArrayList<double[]>();
......
...@@ -470,6 +470,11 @@ public class GurobiHook implements ILPSolver { ...@@ -470,6 +470,11 @@ public class GurobiHook implements ILPSolver {
return 0; return 0;
} }
@Override
public double objectiveCoeff(int index) {
return 0;
}
/** /**
* Given an array of variable indexes, this method returns the corresponding Gurobi variable * Given an array of variable indexes, this method returns the corresponding Gurobi variable
......
...@@ -161,6 +161,11 @@ public interface ILPSolver { ...@@ -161,6 +161,11 @@ public interface ILPSolver {
public double objectiveValue(); public double objectiveValue();
/**
* The coefficient of the variable in the objective function.
*/
public double objectiveCoeff(int index);
/** /**
* This method clears the all constraints and variables out of the ILP solver's problem * This method clears the all constraints and variables out of the ILP solver's problem
* representation, bringing the <code>ILPSolver</code> instance back to the state it was in when * representation, bringing the <code>ILPSolver</code> instance back to the state it was in when
......
...@@ -137,6 +137,11 @@ public class JLISCuttingPlaneILPSolverGurobi implements ILPSolver { ...@@ -137,6 +137,11 @@ public class JLISCuttingPlaneILPSolverGurobi implements ILPSolver {
return baseSolver.objectiveValue(); return baseSolver.objectiveValue();
} }
@Override
public double objectiveCoeff(int index) {
return 0;
}
public void reset() { public void reset() {
baseSolver.reset(); baseSolver.reset();
......
...@@ -21,9 +21,6 @@ public class OJalgoHook implements ILPSolver { ...@@ -21,9 +21,6 @@ public class OJalgoHook implements ILPSolver {
private ExpressionsBasedModel model = new ExpressionsBasedModel(); private ExpressionsBasedModel model = new ExpressionsBasedModel();
private String nameOfObjectiveExpression = "objective";
private Expression objectiveFunction = model.getObjectiveExpression();
// Internal flag for keeping optimization state // Internal flag for keeping optimization state
private boolean minimize = true; private boolean minimize = true;
...@@ -301,6 +298,11 @@ public class OJalgoHook implements ILPSolver { ...@@ -301,6 +298,11 @@ public class OJalgoHook implements ILPSolver {
return result.getValue(); return result.getValue();
} }
@Override
public double objectiveCoeff(int index) {
return model.getVariable(index).getContributionWeight().doubleValue();
}
public void reset() { public void reset() {
if(log) if(log)
System.out.println("OJalgoHook: reset()"); System.out.println("OJalgoHook: reset()");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment