Skip to content

Commit

Permalink
Nothing special
Browse files Browse the repository at this point in the history
  • Loading branch information
apete committed Jan 18, 2025
1 parent dab1e7a commit 343d7d6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/ojalgo/optimisation/linear/LinearSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public LinearSolver.Builder equality(final double rhs, final double... factors)
}

@Override
public final LinearFunction<Double> getObjective() {
public LinearFunction<Double> getObjective() {
LinearFunction<Double> retVal = this.getObjective(LinearFunction.class);
if (retVal == null) {
retVal = LinearFunction.factory(this.getFactory()).make(this.countVariables());
Expand All @@ -111,7 +111,7 @@ public final LinearSolver.Builder lower(final double... bounds) {
return this;
}

public final LinearSolver.Builder lower(final double bound) {
public LinearSolver.Builder lower(final double bound) {
double[] lowerBounds = this.getLowerBounds(ZERO).data;
Arrays.fill(lowerBounds, bound);
return this;
Expand All @@ -123,12 +123,12 @@ public final LinearSolver.Builder objective(final double... factors) {
return this;
}

public final LinearSolver.Builder objective(final int index, final double value) {
public LinearSolver.Builder objective(final int index, final double value) {
this.getObjective().linear().set(index, value);
return this;
}

public final LinearSolver.Builder objective(final MatrixStore<Double> mtrxC) {
public LinearSolver.Builder objective(final MatrixStore<Double> mtrxC) {
this.setObjective(LinearSolver.toObjectiveFunction(mtrxC));
return this;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ public final LinearSolver.Builder upper(final double... bounds) {
return this;
}

public final LinearSolver.Builder upper(final double bound) {
public LinearSolver.Builder upper(final double bound) {
double[] upperBounds = this.getUpperBounds(POSITIVE_INFINITY).data;
Arrays.fill(upperBounds, bound);
return this;
Expand Down Expand Up @@ -328,11 +328,11 @@ protected LinearSolver doBuild(final Options options) {
return new SimplexTableauSolver(tableau, options);
}

protected final double[] getLowerBounds() {
protected double[] getLowerBounds() {
return super.getLowerBounds(ZERO).data;
}

protected final double[] getUpperBounds() {
protected double[] getUpperBounds() {
return super.getUpperBounds(POSITIVE_INFINITY).data;
}

Expand Down
57 changes: 28 additions & 29 deletions src/main/java/org/ojalgo/optimisation/linear/LinearStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ public int countVariables() {
return nbVars + nbNegs + nbSlck + nbIdty;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LinearStructure)) {
return false;
}
LinearStructure other = (LinearStructure) obj;
return Objects.equals(constraints, other.constraints) && nbArti == other.nbArti && nbEqus == other.nbEqus && nbIdty == other.nbIdty
&& nbInes == other.nbInes && nbNegs == other.nbNegs && nbSlck == other.nbSlck && nbVars == other.nbVars
&& Arrays.equals(negativePartVariables, other.negativePartVariables) && Arrays.equals(positivePartVariables, other.positivePartVariables);
}

@Override
public EntryPair<ModelEntity<?>, ConstraintType> getConstraint(final int idc) {
return constraints.getEntry(idc);
Expand All @@ -138,6 +152,15 @@ public EntryPair<ModelEntity<?>, ConstraintType> getSlack(final int ids) {
}
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(negativePartVariables);
result = prime * result + Arrays.hashCode(positivePartVariables);
return prime * result + Objects.hash(constraints, nbArti, nbEqus, nbIdty, nbInes, nbNegs, nbSlck, nbVars);
}

@Override
public int indexOf(final int j) {

Expand Down Expand Up @@ -199,6 +222,11 @@ public void setConstraintNegated(final int i, final boolean negated) {
constraints.negated[i] = negated;
}

@Override
public String toString() {
return this.countConstraints() + " x " + this.countVariables();
}

int countVariablesTotally() {
return nbVars + nbNegs + nbSlck + nbIdty + nbArti;
}
Expand All @@ -223,33 +251,4 @@ void setObjectiveAdjustmentFactor(final double multiplierScale) {
constraints.setMultiplierScale(multiplierScale);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(negativePartVariables);
result = prime * result + Arrays.hashCode(positivePartVariables);
result = prime * result + Objects.hash(constraints, nbArti, nbEqus, nbIdty, nbInes, nbNegs, nbSlck, nbVars);
return result;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof LinearStructure)) {
return false;
}
LinearStructure other = (LinearStructure) obj;
return Objects.equals(constraints, other.constraints) && nbArti == other.nbArti && nbEqus == other.nbEqus && nbIdty == other.nbIdty
&& nbInes == other.nbInes && nbNegs == other.nbNegs && nbSlck == other.nbSlck && nbVars == other.nbVars
&& Arrays.equals(negativePartVariables, other.negativePartVariables) && Arrays.equals(positivePartVariables, other.positivePartVariables);
}

@Override
public String toString() {
return this.countConstraints() + " x " + this.countVariables();
}

}
10 changes: 5 additions & 5 deletions src/main/java/org/ojalgo/optimisation/linear/SimplexSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ static <S extends SimplexStore> S build(final ExpressionsBasedModel model, final
Set<IntIndex> fixedVariables = model.getFixedVariables();
List<Variable> freeVariables = model.getFreeVariables();

List<Expression> equalityConstraints = new ArrayList<>();
List<Expression> equalConstraints = new ArrayList<>();
List<Expression> lowerConstraints = new ArrayList<>();
List<Expression> upperConstraints = new ArrayList<>();

model.constraints().map(c -> c.compensate(fixedVariables)).forEach(constraint -> {
model.constraints().map(constraint -> constraint.compensate(fixedVariables)).forEach(constraint -> {
if (constraint.isEqualityConstraint()) {
equalityConstraints.add(constraint);
equalConstraints.add(constraint);
} else {
if (constraint.isLowerConstraint()) {
lowerConstraints.add(constraint);
Expand All @@ -340,7 +340,7 @@ static <S extends SimplexStore> S build(final ExpressionsBasedModel model, final

int nbUpConstr = upperConstraints.size();
int nbLoConstr = lowerConstraints.size();
int nbEqConstr = equalityConstraints.size();
int nbEqConstr = equalConstraints.size();

int nbProbVars = freeVariables.size();
int nbSlckVars = nbUpConstr + nbLoConstr;
Expand Down Expand Up @@ -384,7 +384,7 @@ static <S extends SimplexStore> S build(final ExpressionsBasedModel model, final
}

for (int i = 0; i < nbEqConstr; i++) {
Expression expression = equalityConstraints.get(i);
Expression expression = equalConstraints.get(i);
for (IntIndex key : expression.getLinearKeySet()) {
int column = model.indexOfFreeVariable(key);
double factor = expression.doubleValue(key, true);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ojalgo/type/EnumPartition.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void extract(final E value, final boolean negate, final int[] receiver) {
byte key = (byte) value.ordinal();

for (int i = 0, j = 0; i < myValues.length && j < receiver.length; i++) {
if ((myValues[i] == key) != negate) {
if (myValues[i] == key != negate) {
receiver[j] = i;
j++;
}
Expand Down

0 comments on commit 343d7d6

Please sign in to comment.