-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f236412
commit 16ac156
Showing
6 changed files
with
258 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
<modelVersion>4.0.0</modelVersion> | ||
<groupId>eu.irzinfante</groupId> | ||
<artifactId>fixed-mps</artifactId> | ||
<version>0.9.5</version> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
|
@@ -153,5 +153,4 @@ | |
<url>scm:git:[email protected]:irzinfante/fixed-mps.git</url> | ||
<developerConnection>scm:git:[email protected]:irzinfante/fixed-mps.git</developerConnection> | ||
</scm> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,8 @@ | |
|
||
/** | ||
* @author irzinfante [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public class Constraint { | ||
|
||
|
@@ -13,37 +13,36 @@ public class Constraint { | |
|
||
/** | ||
* @author irzinfante [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public static class ConstraintBuilder { | ||
|
||
private double coeffs[]; | ||
|
||
/** | ||
* Initializes a Constraint object builder | ||
* | ||
* @param coeffs Coefficients of the variables in the | ||
* same order they are added to the Problem object builder. | ||
* Extra coefficients are ignored and, if there are less | ||
* coefficients than variables, missing coefficients | ||
* are set to zero | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Initializes a Constraint object builder | ||
* | ||
* @param coeffs Coefficients of the variables in the | ||
* same order they are added to the Problem object builder. | ||
* Extra coefficients are ignored and, if there are less | ||
* coefficients than variables, missing coefficients | ||
* are set to zero | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public ConstraintBuilder (double ... coeffs) { | ||
|
||
this.coeffs = coeffs; | ||
} | ||
|
||
/** | ||
* Creates an inequation constraint (≤ k) | ||
* | ||
* @param free The free term of the inequation, k | ||
* @return a less-than type constraint | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Creates an inequation constraint (≤ k) | ||
* | ||
* @param free The free term of the inequation, k | ||
* @return a less-than type constraint | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public Constraint lessThan(double free) { | ||
|
||
Constraint constraint = new Constraint(); | ||
|
@@ -56,13 +55,13 @@ public Constraint lessThan(double free) { | |
} | ||
|
||
/** | ||
* Creates an inequation constraint (≥ k) | ||
* | ||
* @param free The free term of the inequation, k | ||
* @return a greater-than type constraint | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Creates an inequation constraint (≥ k) | ||
* | ||
* @param free The free term of the inequation, k | ||
* @return a greater-than type constraint | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public Constraint greaterThan(double free) { | ||
|
||
Constraint constraint = new Constraint(); | ||
|
@@ -75,13 +74,13 @@ public Constraint greaterThan(double free) { | |
} | ||
|
||
/** | ||
* Creates a equation constraint | ||
* | ||
* @param free The free term of the equation | ||
* @return a equality type constraint | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Creates a equation constraint | ||
* | ||
* @param free The free term of the equation | ||
* @return a equality type constraint | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public Constraint equalTo(double free) { | ||
|
||
Constraint constraint = new Constraint(); | ||
|
@@ -97,29 +96,29 @@ public Constraint equalTo(double free) { | |
|
||
private Constraint() { | ||
} | ||
|
||
public double[] getCoeffs() { | ||
return coeffs; | ||
} | ||
|
||
private void setCoeffs(double coeffs[]) { | ||
this.coeffs = coeffs; | ||
} | ||
|
||
public char getType() { | ||
return type; | ||
} | ||
|
||
private void setType(char type) { | ||
this.type = type; | ||
} | ||
|
||
public double getFree() { | ||
return free; | ||
} | ||
|
||
private void setFree(double free) { | ||
this.free = free; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,18 @@ | |
|
||
/** | ||
* @author irzinfante [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public class Problem { | ||
|
||
private Variable columns[]; | ||
private Constraint rows[]; | ||
|
||
/** | ||
* @author irzinfante [email protected] | ||
* @version 1.0 | ||
* @since 1.0 | ||
* @version 1.0.0 | ||
* @since 1.0.0 | ||
*/ | ||
public static class ProblemBuilder { | ||
|
||
|
@@ -26,12 +26,12 @@ public static class ProblemBuilder { | |
private int numVar; | ||
|
||
/** | ||
* Initializes a Problem object builder | ||
* | ||
* @param variables Variables of the problem | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Initializes a Problem object builder | ||
* | ||
* @param variables Variables of the problem | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public ProblemBuilder(Variable ... variables) { | ||
|
||
this.columns = variables; | ||
|
@@ -40,13 +40,13 @@ public ProblemBuilder(Variable ... variables) { | |
} | ||
|
||
/** | ||
* Adds a constraint to the problem | ||
* | ||
* @param constraint Constraint to add to the problem | ||
* @return ProblemBuilder with the added constraint | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Adds a constraint to the problem | ||
* | ||
* @param constraint Constraint to add to the problem | ||
* @return ProblemBuilder with the added constraint | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public ProblemBuilder addConstraint(Constraint constraint) { | ||
|
||
double coeffs[] = new double[numVar]; | ||
|
@@ -55,60 +55,61 @@ public ProblemBuilder addConstraint(Constraint constraint) { | |
} | ||
|
||
switch (constraint.getType()) { | ||
case 'E': | ||
rows.add(new ConstraintBuilder(coeffs).equalTo(constraint.getFree())); | ||
break; | ||
case 'L': | ||
rows.add(new ConstraintBuilder(coeffs).lessThan(constraint.getFree())); | ||
break; | ||
case 'G': | ||
rows.add(new ConstraintBuilder(coeffs).greaterThan(constraint.getFree())); | ||
break; | ||
case 'E': | ||
rows.add(new ConstraintBuilder(coeffs).equalTo(constraint.getFree())); | ||
break; | ||
case 'L': | ||
rows.add(new ConstraintBuilder(coeffs).lessThan(constraint.getFree())); | ||
break; | ||
case 'G': | ||
rows.add(new ConstraintBuilder(coeffs).greaterThan(constraint.getFree())); | ||
break; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Returns the created Problem object | ||
* | ||
* @return LP problem | ||
* | ||
* @since 1.0 | ||
*/ | ||
* Returns the created Problem object | ||
* | ||
* @return LP problem | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public Problem build() { | ||
|
||
Problem lp = new Problem(); | ||
Constraint rows[] = new Constraint[this.rows.size()]; | ||
for(int i = 0; i < this.rows.size(); i++) { | ||
rows[i] = this.rows.get(i); | ||
} | ||
|
||
lp.setColumns(this.columns); | ||
lp.setRows(rows); | ||
|
||
return lp; | ||
Problem lp = new Problem(); | ||
Constraint rows[] = new Constraint[this.rows.size()]; | ||
for(int i = 0; i < this.rows.size(); i++) { | ||
rows[i] = this.rows.get(i); | ||
} | ||
lp.setColumns(this.columns); | ||
lp.setRows(rows); | ||
return lp; | ||
} | ||
|
||
} | ||
|
||
private Problem() { | ||
} | ||
|
||
public Variable[] getColumns() { | ||
return columns; | ||
} | ||
|
||
private void setColumns(Variable[] columns) { | ||
this.columns = columns; | ||
} | ||
|
||
public Constraint[] getRows() { | ||
return rows; | ||
} | ||
|
||
private void setRows(Constraint rows[]) { | ||
this.rows = rows; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.