From d46f209f3202b79488b8598d06d0c1d2cdf95816 Mon Sep 17 00:00:00 2001 From: Thomas <thomas.musset@pasteur.fr> Date: Tue, 2 Jul 2024 19:33:35 +0200 Subject: [PATCH] updated pom to v2.0.0-a.1, fix classes accordingly to new architecture, added icon, updated .gitignore --- .gitignore | 41 ++- pom.xml | 6 +- .../CanonicalProgramParameters.java | 3 +- .../CanonicalSimplexProgram.java | 274 ++++++++++-------- .../LinearProgrammingICYPlugin.java | 18 +- .../SimplexBLAND.java | 8 +- .../SimplexLEXICO.java | 8 +- .../SimplexMAX.java | 8 +- .../TableauMinSlackObjective.java | 7 +- .../TableauWithSlackVariables.java | 46 +-- src/main/resources/linear-programming.png | Bin 0 -> 3286 bytes 11 files changed, 251 insertions(+), 168 deletions(-) create mode 100644 src/main/resources/linear-programming.png diff --git a/.gitignore b/.gitignore index b0a9905..57f16fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,41 @@ -.idea/ -.settings/ -build/ +/build* +/workspace +setting.xml +release/ target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +icy.log + +### IntelliJ IDEA ### +.idea/ +*.iws *.iml +*.ipr + +### Eclipse ### +.apt_generated .classpath +.factorypath .project -**/.DS_Store \ No newline at end of file +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +**/.DS_Store +Icon? \ No newline at end of file diff --git a/pom.xml b/pom.xml index 18fcc24..4ae3a2f 100644 --- a/pom.xml +++ b/pom.xml @@ -7,11 +7,11 @@ <parent> <groupId>org.bioimageanalysis.icy</groupId> <artifactId>pom-icy</artifactId> - <version>2.2.0</version> + <version>3.0.0-a.1</version> </parent> <artifactId>linear-programming</artifactId> - <version>2.0.0</version> + <version>2.0.0-a.1</version> <name>Linear Programming</name> <description> @@ -26,7 +26,7 @@ <repositories> <repository> <id>icy</id> - <url>https://icy-nexus.pasteur.fr/repository/Icy/</url> + <url>https://nexus-icy.pasteur.cloud/repository/icy/</url> </repository> </repositories> </project> \ No newline at end of file diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalProgramParameters.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalProgramParameters.java index 2c85ae2..3ace13d 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalProgramParameters.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalProgramParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -45,7 +45,6 @@ package plugins.nchenouard.linearprogrammingfullsimplex; * * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ - public class CanonicalProgramParameters { /** * The objective function coefficient: c'*x or sum_i c[i]*x[i] for the variable x. diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalSimplexProgram.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalSimplexProgram.java index d54cfb9..64ddf5e 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalSimplexProgram.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/CanonicalSimplexProgram.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,7 +18,9 @@ package plugins.nchenouard.linearprogrammingfullsimplex; -import icy.system.IcyExceptionHandler; +import org.bioimageanalysis.icy.system.logging.IcyLogger; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import java.io.*; @@ -45,7 +47,6 @@ import java.io.*; * * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ - public abstract class CanonicalSimplexProgram { /** * Parameters defining the linear programming problem @@ -86,7 +87,7 @@ public abstract class CanonicalSimplexProgram { * @param equality indicates whether each constraint is an equality. Else it is * <=. */ - public CanonicalSimplexProgram(final double[][] A, final double[] b, final double[] c, final boolean maximization, final boolean[] equality) { + public CanonicalSimplexProgram(final double[][] A, final double @NotNull [] b, final double @NotNull [] c, final boolean maximization, final boolean[] equality) { this.parameters = new CanonicalProgramParameters(); this.parameters.A = A; this.parameters.b = b; @@ -102,7 +103,8 @@ public abstract class CanonicalSimplexProgram { * * @param p Parameters of the linear programming problem. */ - public CanonicalSimplexProgram(final CanonicalProgramParameters p) { + @Contract(pure = true) + public CanonicalSimplexProgram(final @NotNull CanonicalProgramParameters p) { this.parameters = p; this.numVariables = p.c.length; this.numConstraints = p.b.length; @@ -224,7 +226,7 @@ public abstract class CanonicalSimplexProgram { // Canonical form: initial tableau is built by introducing unit vectors solvePhaseICanonicalSimplex(); if (verbose) { - System.out.println("Tableau after phase 1 :"); + IcyLogger.trace(this.getClass(), "Tableau after phase 1: "); tableau0.printTableau(); } // Phase II: optimisation by Gauss-Jordan replacement of non-basic columns @@ -269,7 +271,7 @@ public abstract class CanonicalSimplexProgram { if (!success) return false; if (verbose) { - System.out.println("Phase 1 "); + IcyLogger.trace(this.getClass(), "Phase 1 "); tableau0.printTableau(); } if (Math.abs(tableau0.scoreValue) < tol) // optimal score should be 0 @@ -337,22 +339,22 @@ public abstract class CanonicalSimplexProgram { } else { if (verbose) - System.out.println("replacement: row = " + rowIdx + ", column = " + colIdx); + IcyLogger.trace(this.getClass(), "replacement: row = " + rowIdx + ", column = " + colIdx); tableau.pivot(colIdx, rowIdx); } } if (verbose) { - System.out.println("Tableau at iteration:"); + IcyLogger.trace(this.getClass(), "Tableau at iteration: "); tableau.printTableau(); } } if (verbose) { - System.out.println("Final tableau:"); + IcyLogger.trace(this.getClass(), "Final tableau: "); tableau.printTableau(); } if (!feasible) { if (verbose) - System.out.println("UNFEASIBLE problem"); + IcyLogger.trace(this.getClass(), "UNFEASIBLE problem"); return false; } else { @@ -404,7 +406,7 @@ public abstract class CanonicalSimplexProgram { for (int j = 0; j < solution.length; j++) { v += A0[i][j] * solution[j]; } - System.out.println(v + "<?>" + b0[i]); + IcyLogger.info(this.getClass(), v + "<?>" + b0[i]); } } } @@ -465,36 +467,35 @@ public abstract class CanonicalSimplexProgram { public void displayProblem() { - System.out.println("Linear Programming problem max c'x st. Ax <= b, x >= 0 and some equality contraints defined by eq"); + IcyLogger.info(this.getClass(), "Linear Programming problem max c'x st. Ax <= b, x >= 0 and some equality contraints defined by eq"); if (parameters.maximization) - System.out.println("Maximization problem"); + IcyLogger.info(this.getClass(), "Maximization problem"); else - System.out.println("Minimization problem"); - System.out.print("c = ["); + IcyLogger.info(this.getClass(), "Minimization problem"); + IcyLogger.info(this.getClass(), "c = ["); for (int i = 0; i < parameters.c.length; i++) - System.out.print(parameters.c[i] + ", "); - System.out.println("]"); - System.out.print("b = ["); + IcyLogger.info(this.getClass(), parameters.c[i] + ", "); + IcyLogger.info(this.getClass(), "]"); + IcyLogger.info(this.getClass(), "b = ["); for (int i = 0; i < parameters.b.length; i++) - System.out.print(parameters.b[i] + ", "); - System.out.println("]"); - System.out.print("eq = ["); + IcyLogger.info(this.getClass(), parameters.b[i] + ", "); + IcyLogger.info(this.getClass(), "]"); + IcyLogger.info(this.getClass(), "eq = ["); for (int i = 0; i < parameters.equalityConstraints.length; i++) - System.out.print(parameters.equalityConstraints[i] + ", "); - System.out.println("]"); - System.out.print("A = ["); + IcyLogger.info(this.getClass(), parameters.equalityConstraints[i] + ", "); + IcyLogger.info(this.getClass(), "]"); + IcyLogger.info(this.getClass(), "A = ["); for (int i = 0; i < parameters.A.length; i++) { - System.out.print("["); + IcyLogger.info(this.getClass(), "["); for (int j = 0; j < parameters.A[i].length; j++) - System.out.print(parameters.A[i][j] + ", "); - System.out.println("],"); + IcyLogger.info(this.getClass(), parameters.A[i][j] + ", "); + IcyLogger.info(this.getClass(), "],"); } - System.out.println("]"); + IcyLogger.info(this.getClass(), "]"); } public void displayProblemTutorial() { - System.out.println("Linear Programming problem:"); - System.out.println(); + IcyLogger.info(this.getClass(), "Linear Programming problem:"); StringBuilder line = new StringBuilder(); if (parameters.maximization) line.append("max_x"); @@ -507,10 +508,8 @@ public abstract class CanonicalSimplexProgram { else line.append(" - ").append(Math.abs(parameters.c[i])).append("*x[").append(i).append("]"); } - System.out.println(line); - System.out.println(); - System.out.println("Such that x >= 0 and:"); - System.out.println(); + IcyLogger.info(this.getClass(), line.toString()); + IcyLogger.info(this.getClass(), "Such that x >= 0 and:"); for (int i = 0; i < parameters.b.length; i++) { line = new StringBuilder(); for (int j = 0; j < parameters.A[i].length; j++) { @@ -524,7 +523,7 @@ public abstract class CanonicalSimplexProgram { else line.append(" <= "); line.append(parameters.b[i]); - System.out.println(line); + IcyLogger.info(this.getClass(), line.toString()); } } @@ -532,30 +531,31 @@ public abstract class CanonicalSimplexProgram { * @return Manual of the library for stand-alone use through command line */ public static String getHelp() { - return "Run the solver for example problems or for a user-defined system\n" - + "Empty arguments to use the default example.\n" - + "Enter an integer from 0 to 3 for different example scenarios.\n" - + "Enter -1 for a user-defined scenario through text files.\n " - + "For custom scenarios, enter filenames (text files) for different parameters of the problem preceded by the appropriate prefix:\n" - + "-c for the objective function file.\n" - + "-A for constraint matrix file.\n" - + "-b for the constraint value file.\n" - + "-e for the equality constraint file.\n" - + "-max or -min to indicate a maximization or minimization problem, respectively. Default in minimization.\n" - + "Example arguments: java -jar linearProgrammingICY.jar -c c.txt -A A.txt -b b.txt -e eq.txt -max -o solution.txt" - + "Each text file must contain a series of double values separated by ',' in a single line, except for the constraint file which contains one line per constraint.\n" - + "For the equality file '0' stands for 'false' and '1' for true.\n\n" - + "Version 1.0. April 2014. Author: Nicolas Chenouard. nicolas.chenouard.dev@gmail.com. Licence GPL V3.0"; + return """ + Run the solver for example problems or for a user-defined system + Empty arguments to use the default example. + Enter an integer from 0 to 3 for different example scenarios. + Enter -1 for a user-defined scenario through text files. + For custom scenarios, enter filenames (text files) for different parameters of the problem preceded by the appropriate prefix: + -c for the objective function file. + -A for constraint matrix file. + -b for the constraint value file. + -e for the equality constraint file. + -max or -min to indicate a maximization or minimization problem, respectively. Default in minimization. + Example arguments: java -jar linearProgrammingICY.jar -c c.txt -A A.txt -b b.txt -e eq.txt -max -o solution.txt\ + Each text file must contain a series of double values separated by ',' in a single line, except for the constraint file which contains one line per constraint. + For the equality file '0' stands for 'false' and '1' for true. + + Version 1.0. April 2014. Author: Nicolas Chenouard. nicolas.chenouard.dev@gmail.com. Licence GPL V3.0"""; } /** * Display the manual of the library for stand-alone use through command line */ public static void displayHelp() { - System.out.println(getHelp()); + IcyLogger.info(CanonicalSimplexProgram.class, getHelp()); } - /** * Run the solver for example problems or for a user-defined system * @@ -575,7 +575,7 @@ public abstract class CanonicalSimplexProgram { * Each text file must contain a series of double values separated by ',' in a single line, except for the constraint file which contains one line per constraint. * For the equality file '0' stands for 'false' and '1' for true. */ - public static void main(final String[] args) { + public static void main(final String @NotNull [] args) { int scenario = 0; if (args.length > 0) { if (args[0].compareTo("-h") == 0 || args[0].compareTo("-help") == 0 || args[0].compareTo("--h") == 0 || args[0].compareTo("--help") == 0) { @@ -587,20 +587,28 @@ public abstract class CanonicalSimplexProgram { scenario = Integer.parseInt(args[0]); } catch (final NumberFormatException e) { - System.out.println("Invalid input argument"); - System.out.println("Use input option -help to display the manual of the software"); - IcyExceptionHandler.showErrorMessage(e, true); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Invalid input argument", + "Use input option -help to display the manual of the software" + ); return; } } } else { - System.out.println("Solving a default simple linear problem with the Simplex algorithm."); - System.out.println("Enter -help for the manual explicating the customization options."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "Solving a default simple linear problem with the Simplex algorithm.", + "Enter -help for the manual explicating the customization options." + ); } if (scenario < -1 || scenario > 3) { - System.out.println("Invalid input argument"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Invalid input argument", + "Use input option -help to display the manual of the software" + ); return; } boolean maximization = false; @@ -633,8 +641,11 @@ public abstract class CanonicalSimplexProgram { } } if (fileA == null) { - System.out.println("Missing -A input argument"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Missing -A input argument", + "Use input option -help to display the manual of the software" + ); return; } String fileB = null; @@ -645,8 +656,11 @@ public abstract class CanonicalSimplexProgram { } } if (fileB == null) { - System.out.println("Missing -b input argument"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Missing -b input argument", + "Use input option -help to display the manual of the software" + ); return; } @@ -658,8 +672,11 @@ public abstract class CanonicalSimplexProgram { } } if (fileC == null) { - System.out.println("Missing -c input argument"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Missing -c input argument", + "Use input option -help to display the manual of the software" + ); return; } for (int i = 0; i < args.length - 1; i++) { @@ -676,8 +693,11 @@ public abstract class CanonicalSimplexProgram { } } if (fileE == null) { - System.out.println("Missing -e input argument"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Missing -e input argument", + "Use input option -help to display the manual of the software" + ); return; } try { @@ -738,15 +758,18 @@ public abstract class CanonicalSimplexProgram { fis.close(); } catch (final IOException e) { - IcyExceptionHandler.showErrorMessage(e, true); + IcyLogger.error(CanonicalSimplexProgram.class, e); return; } break; } case 0: { - System.out.println("Basic example with 3 pivots"); - System.out.println("Optimal is 6.5"); - System.out.println("Solution is [1.0, 1.0, 0.5, 0.0]"); + IcyLogger.info( + CanonicalSimplexProgram.class, + "Basic example with 3 pivots", + "Optimal is 6.5", + "Solution is [1.0, 1.0, 0.5, 0.0]" + ); A = new double[][]{{2, 1, 0, 0}, {0, 1, 4, 1}, {1, 3, 0, 1} @@ -758,9 +781,12 @@ public abstract class CanonicalSimplexProgram { break; } case 1: { - System.out.println("Example that would cycle with Bland rule."); - System.out.println("Optimal score is 1/20."); - System.out.println("Solution is [1/25, 0, 1, 0]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "Example that would cycle with Bland rule.", + "Optimal score is 1/20.", + "Solution is [1/25, 0, 1, 0]." + ); A = new double[][]{{1d / 4, -60, -1d / 25, 9}, {1d / 2, -90, -1d / 50, 3}, {0, 0, 1, 0} @@ -772,8 +798,11 @@ public abstract class CanonicalSimplexProgram { break; } case 2: { - System.out.println("An example with equality constraints"); - System.out.println("Solution is [0, 4/7, 1 + 5/7, 0, 0]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "An example with equality constraints", + "Solution is [0, 4/7, 1 + 5/7, 0, 0]." + ); A = new double[][] {{5, -4, 13, -2, 1}, {1, -1, 5, -1, 1}, @@ -785,9 +814,12 @@ public abstract class CanonicalSimplexProgram { break; } case 3: { - System.out.println("An example with equality constraints and negative right-hand-side"); - System.out.println("Optimal score is -3 - 1/16."); - System.out.println("Solution is [3/16, 1 + 1/4, 0, 5/16]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "An example with equality constraints and negative right-hand-side", + "Optimal score is -3 - 1/16.", + "Solution is [3/16, 1 + 1/4, 0, 5/16]." + ); A = new double[][] {{1, 2, 1, 1}, {1, -2, 2, 1}, @@ -800,8 +832,11 @@ public abstract class CanonicalSimplexProgram { } } if (A == null || b == null || c == null || equality == null) { - System.out.println("Missing arguments"); - System.out.println("Use input option -help to display the manual of the software"); + IcyLogger.error( + CanonicalSimplexProgram.class, + "Missing arguments", + "Use input option -help to display the manual of the software" + ); return; } final CanonicalSimplexProgram program = new SimplexLEXICO(A, b, c, maximization, equality); @@ -811,21 +846,21 @@ public abstract class CanonicalSimplexProgram { if (program.solvePrimalSimplex()) { final double[] solution = program.solution; if (verbose) { - System.out.print("Computed solution = ["); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed solution = ["); for (final double value : solution) - System.out.print(value + ", "); - System.out.println("]"); - System.out.println("Computed score = " + program.tableau0.scoreValue); - System.out.println("Computed constraint values:"); + IcyLogger.trace(CanonicalSimplexProgram.class, value + ", "); + IcyLogger.trace(CanonicalSimplexProgram.class, "]"); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed score = " + program.tableau0.scoreValue); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed constraint values:"); for (int i = 0; i < A.length; i++) { double v = 0; // compute the constraint for (int j = 0; j < A[i].length; j++) v += A[i][j] * solution[j]; if (equality[i]) - System.out.println(v + " == " + b[i]); + IcyLogger.trace(CanonicalSimplexProgram.class, v + " == " + b[i]); else - System.out.println(v + " <= " + b[i]); + IcyLogger.trace(CanonicalSimplexProgram.class, v + " <= " + b[i]); } } if (outputFile != null) { @@ -841,19 +876,18 @@ public abstract class CanonicalSimplexProgram { out.close(); } catch (final IOException e) { - IcyExceptionHandler.showErrorMessage(e, true); + IcyLogger.error(CanonicalSimplexProgram.class, e); } } } else { - System.out.println("Solve simplex failed"); + IcyLogger.error(CanonicalSimplexProgram.class, "Solve simplex failed"); } } public static void runExampleScenario(final int scenario) { if (scenario < 0 || scenario > 3) { - System.out.println("Invalid input argument"); - System.out.println("Scenario indices are: 0, 1, 2 and 3"); + IcyLogger.error(CanonicalSimplexProgram.class, "Invalid input argument", "Scenario indices are: 0, 1, 2 and 3"); return; } boolean maximization = false; @@ -864,9 +898,12 @@ public abstract class CanonicalSimplexProgram { final boolean verbose = true; switch (scenario) { case 0: { - System.out.println("Basic example with 3 pivots"); - System.out.println("Optimal score is 6.5"); - System.out.println("Solution is [1.0, 1.0, 0.5, 0.0]"); + IcyLogger.info( + CanonicalSimplexProgram.class, + "Basic example with 3 pivots", + "Optimal score is 6.5", + "Solution is [1.0, 1.0, 0.5, 0.0]" + ); A = new double[][]{{2, 1, 0, 0}, {0, 1, 4, 1}, {1, 3, 0, 1} @@ -878,9 +915,12 @@ public abstract class CanonicalSimplexProgram { break; } case 1: { - System.out.println("Example that would cycle with Bland rule."); - System.out.println("Optimal score is 1/20."); - System.out.println("Solution is [1/25, 0, 1, 0]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "Example that would cycle with Bland rule.", + "Optimal score is 1/20.", + "Solution is [1/25, 0, 1, 0]." + ); A = new double[][]{{1d / 4, -60, -1d / 25, 9}, {1d / 2, -90, -1d / 50, 3}, {0, 0, 1, 0} @@ -892,8 +932,11 @@ public abstract class CanonicalSimplexProgram { break; } case 2: { - System.out.println("An example with equality constraints"); - System.out.println("Solution is [0, 4/7, 1 + 5/7, 0, 0]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "An example with equality constraints", + "Solution is [0, 4/7, 1 + 5/7, 0, 0]." + ); A = new double[][] {{5, -4, 13, -2, 1}, {1, -1, 5, -1, 1}, @@ -905,9 +948,12 @@ public abstract class CanonicalSimplexProgram { break; } case 3: { - System.out.println("An example with equality constraints and negative right-hand-side"); - System.out.println("Optimal score is -3 - 1/16."); - System.out.println("Solution is [3/16, 1 + 1/4, 0, 5/16]."); + IcyLogger.info( + CanonicalSimplexProgram.class, + "An example with equality constraints and negative right-hand-side", + "Optimal score is -3 - 1/16.", + "Solution is [3/16, 1 + 1/4, 0, 5/16]." + ); A = new double[][] {{1, 2, 1, 1}, {1, -2, 2, 1}, @@ -922,35 +968,31 @@ public abstract class CanonicalSimplexProgram { } final CanonicalSimplexProgram program = new SimplexLEXICO(A, b, c, maximization, equality); if (verbose) { - System.out.println(); program.displayProblemTutorial(); } if (program.solvePrimalSimplex()) { final double[] solution = program.solution; if (verbose) { - System.out.println(); - System.out.print("Computed solution = ["); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed solution = ["); for (final double value : solution) - System.out.print(value + ", "); - System.out.println("]"); - System.out.println(); - System.out.println("Computed score = " + program.tableau0.scoreValue); - System.out.println(); - System.out.println("Computed constraint values:"); + IcyLogger.trace(CanonicalSimplexProgram.class, value + ", "); + IcyLogger.trace(CanonicalSimplexProgram.class, "]"); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed score = " + program.tableau0.scoreValue); + IcyLogger.trace(CanonicalSimplexProgram.class, "Computed constraint values:"); for (int i = 0; i < A.length; i++) { double v = 0; // compute the constraint for (int j = 0; j < A[i].length; j++) v += A[i][j] * solution[j]; if (equality[i]) - System.out.println(v + " == " + b[i]); + IcyLogger.trace(CanonicalSimplexProgram.class, v + " == " + b[i]); else - System.out.println(v + " <= " + b[i]); + IcyLogger.trace(CanonicalSimplexProgram.class, v + " <= " + b[i]); } } } else { - System.out.println("Solve simplex failed"); + IcyLogger.error(CanonicalSimplexProgram.class, "Solve simplex failed"); } } } \ No newline at end of file diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/LinearProgrammingICYPlugin.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/LinearProgrammingICYPlugin.java index 728b638..b3df71c 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/LinearProgrammingICYPlugin.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/LinearProgrammingICYPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,20 +18,22 @@ package plugins.nchenouard.linearprogrammingfullsimplex; -import icy.gui.frame.progress.AnnounceFrame; -import icy.plugin.abstract_.PluginActionable; +import org.bioimageanalysis.icy.extension.plugin.abstract_.PluginActionable; +import org.bioimageanalysis.icy.extension.plugin.annotation_.IcyPluginIcon; +import org.bioimageanalysis.icy.extension.plugin.annotation_.IcyPluginName; +import org.bioimageanalysis.icy.gui.frame.progress.AnnounceFrame; +import org.bioimageanalysis.icy.system.logging.IcyLogger; +@IcyPluginName("Linear Programming Example") +@IcyPluginIcon(path = "/linear-programming.png") public class LinearProgrammingICYPlugin extends PluginActionable { @Override public void run() { new AnnounceFrame("It is now running a series of example optimization problems. See the console for the output."); - new AnnounceFrame("This is a utility plugin, intended to be used by other ICY plugins."); + new AnnounceFrame("This is an utility plugin, intended to be used by other ICY plugins."); for (int i = 0; i < 3; i++) { - System.out.println(); - System.out.println("=== Linear Programming test scenario " + i + " ==="); - System.out.println(); + IcyLogger.info(this.getClass(), "=== Linear Programming test scenario " + i + " ==="); CanonicalSimplexProgram.runExampleScenario(i); } } - } diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexBLAND.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexBLAND.java index a92558a..79b2b28 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexBLAND.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexBLAND.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,12 +18,14 @@ package plugins.nchenouard.linearprogrammingfullsimplex; +import org.jetbrains.annotations.NotNull; + /** * Implements the Bland rule for pivoting for the Simplex algorithm. * <p> * Warning: this rule shows high probability of cycling. * <p> - * Part of the Linear Programming plugin for ICY http://icy.bioimageanalysis.org + * Part of the Linear Programming plugin for ICY <a href="https://icy.bioimageanalysis.org">https://icy.bioimageanalysis.org</a> * * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ @@ -59,7 +61,7 @@ public class SimplexBLAND extends CanonicalSimplexProgram { * @return the row index in the tableau */ @Override - protected int getRowidx(final TableauWithSlackVariables tableau, final int colIdx) { + protected int getRowidx(final @NotNull TableauWithSlackVariables tableau, final int colIdx) { boolean found = false; double maxVal = -1; int rowIdx = -1; diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexLEXICO.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexLEXICO.java index 172848c..61f7840 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexLEXICO.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexLEXICO.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,12 +18,14 @@ package plugins.nchenouard.linearprogrammingfullsimplex; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; /** * Implements the lexicographic rule for pivoting for the Simplex algorithm. * <p> - * Part of the Linear Programming plugin for ICY http://icy.bioimageanalysis.org + * Part of the Linear Programming plugin for ICY <a href="https://icy.bioimageanalysis.org">https://icy.bioimageanalysis.org</a> * * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ @@ -100,7 +102,7 @@ public class SimplexLEXICO extends CanonicalSimplexProgram { * @return the row index in the tableau */ @Override - protected int getRowidx(final TableauWithSlackVariables tableau, final int colIdx) { + protected int getRowidx(final @NotNull TableauWithSlackVariables tableau, final int colIdx) { int rowIdx = -1; int numBasicRow = 0; final ArrayList<Integer> basicCols = new ArrayList<>(); diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexMAX.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexMAX.java index a65f066..e1a13e3 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexMAX.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/SimplexMAX.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,12 +18,14 @@ package plugins.nchenouard.linearprogrammingfullsimplex; +import org.jetbrains.annotations.NotNull; + /** * Implements the maximum score rule for pivoting for the Simplex algorithm. * <p> * Warning: this rule shows high probability of cycling. * <p> - * Part of the Linear Programming plugin for ICY http://icy.bioimageanalysis.org + * Part of the Linear Programming plugin for ICY <a href="https://icy.bioimageanalysis.org">https://icy.bioimageanalysis.org</a> * * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ @@ -96,7 +98,7 @@ public class SimplexMAX extends CanonicalSimplexProgram { * @return the row index in the tableau */ @Override - protected int getRowidx(final TableauWithSlackVariables tableau, final int colIdx) { + protected int getRowidx(final @NotNull TableauWithSlackVariables tableau, final int colIdx) { boolean found = false; double maxVal = -1; int rowIdx = -1; diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauMinSlackObjective.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauMinSlackObjective.java index 55a2ac2..d386e2c 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauMinSlackObjective.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauMinSlackObjective.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,6 +18,8 @@ package plugins.nchenouard.linearprogrammingfullsimplex; +import org.jetbrains.annotations.NotNull; + /** * Tableau used for Gauss-Jordan elimination in which slack variables are given a 1 score depending on whether constraints are equalities. * Slack variables are added to the set of column vectors in a leading position. @@ -27,7 +29,6 @@ package plugins.nchenouard.linearprogrammingfullsimplex; * @author Nicolas Chenouard (nicolas.chenouard.dev@gmail.com) */ public class TableauMinSlackObjective extends TableauWithSlackVariables { - /** * Create the tableau based on a linear program. The scores in the tableau * will not be initialized to their standard value but set to handle @@ -35,7 +36,7 @@ public class TableauMinSlackObjective extends TableauWithSlackVariables { * * @param simplexProgram parameters defining the linear optimization problem. */ - public TableauMinSlackObjective(final CanonicalSimplexProgram simplexProgram) { + public TableauMinSlackObjective(final @NotNull CanonicalSimplexProgram simplexProgram) { super(simplexProgram.parameters.A); // now make the slacks feasible xCol = simplexProgram.parameters.b.clone(); // equal to b since we start with unit vectors as initial left vectors diff --git a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauWithSlackVariables.java b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauWithSlackVariables.java index 110f17d..f22c28d 100644 --- a/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauWithSlackVariables.java +++ b/src/main/java/plugins/nchenouard/linearprogrammingfullsimplex/TableauWithSlackVariables.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2023. Institut Pasteur. + * Copyright (c) 2010-2024. Institut Pasteur. * * This file is part of Icy. * Icy is free software: you can redistribute it and/or modify @@ -18,6 +18,9 @@ package plugins.nchenouard.linearprogrammingfullsimplex; +import org.bioimageanalysis.icy.system.logging.IcyLogger; +import org.jetbrains.annotations.NotNull; + /** * Tableau used for Gauss-Jordan elimination. * Initial basis is built by using slack variables. @@ -88,7 +91,7 @@ public class TableauWithSlackVariables { * * @param parameters parameters defining the linear optimization problem. */ - public TableauWithSlackVariables(final CanonicalProgramParameters parameters) { + public TableauWithSlackVariables(final @NotNull CanonicalProgramParameters parameters) { createVectors(parameters.A); // constraint value column xCol = parameters.b.clone(); // equal to b since we start with unit vectors as initial left vectors // build the score row @@ -141,7 +144,7 @@ public class TableauWithSlackVariables { * * @param A Constraint matrix. Each element A[i] defines a linear combination of the variable corresponding to a constraint. */ - protected void createVectors(final double[][] A) { + protected void createVectors(final double @NotNull [] @NotNull [] A) { final int numConstraints = A.length; numVariables = A[0].length; numCol = numConstraints + numVariables; @@ -174,42 +177,39 @@ public class TableauWithSlackVariables { * Print the tableau */ public void printTableau() { - System.out.println("Column vectors"); + IcyLogger.trace(this.getClass(), "Column vectors"); for (int i = 0; i < columnVectors.length; i++) { final double[] vector = columnVectors[i]; - System.out.print("a" + i + " = ["); + IcyLogger.trace(this.getClass(), "a" + i + " = ["); for (final double v : vector) - System.out.print(v + ", "); - System.out.println("]'"); + IcyLogger.trace(this.getClass(), v + ", "); + IcyLogger.trace(this.getClass(), "]'"); } - System.out.println("Basis vectors"); + IcyLogger.trace(this.getClass(), "Basis vectors"); for (int i = 0; i < leftVectorsIdx.length; i++) { final double[] vector = columnVectors[leftVectorsIdx[i]]; - System.out.print("v" + i + " = ["); + IcyLogger.trace(this.getClass(), "v" + i + " = ["); for (final double v : vector) - System.out.print(v + ", "); - System.out.println("]'"); + IcyLogger.trace(this.getClass(), v + ", "); + IcyLogger.trace(this.getClass(), "]'"); } - System.out.println("Tableau"); + IcyLogger.trace(this.getClass(), "Tableau"); for (final double[] doubles : tableau) { for (final double aDouble : doubles) - System.out.print(aDouble + " "); - System.out.println(); + IcyLogger.trace(this.getClass(), aDouble + " "); } - System.out.println(); - System.out.print("x = ["); + IcyLogger.trace(this.getClass(), "x = ["); for (final double v : xCol) - System.out.print(v + ", "); - System.out.println("]'"); + IcyLogger.trace(this.getClass(), v + ", "); + IcyLogger.trace(this.getClass(), "]'"); - System.out.println(); - System.out.print("score row = ["); + IcyLogger.trace(this.getClass(), "score row = ["); for (final double v : scoreRow) - System.out.print(v + ", "); - System.out.println("]'"); + IcyLogger.trace(this.getClass(), v + ", "); + IcyLogger.trace(this.getClass(), "]'"); - System.out.println("Score = " + scoreValue); + IcyLogger.trace(this.getClass(), "Score = " + scoreValue); } /** diff --git a/src/main/resources/linear-programming.png b/src/main/resources/linear-programming.png new file mode 100644 index 0000000000000000000000000000000000000000..1fa196a7fa57ccec31dd2c97d41796e623c8be23 GIT binary patch literal 3286 zcmV;{3@P)8P)<h;3K|Lk000e1NJLTq003YB003YJ0ssI2ZTjGE000b~Nkl<Zc%1B9 z3y@S*dj9@%@40>ZHPbZBV+MzLAc6?Ei-PVNp(tgu8_jMl8^M^ZUCo2lpcN(HZZ_Es zwN+cBlC@HKY$d5|YE87FWsKSAZmls@5sgu6MF|=~8D68n3=H$4ryuv;^GMx$8>WSU z9+)0xp!+MTIeq3n&iU^D{r^4xIekp6HR?Dw*km_gs-sR&1=I<ufI2}HP$#GY>I7B5 znFMLAUDp*tOj3KM9H{;tbbiz&RskafNhtyJ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