This repository provides a basic framework for formulating and solving linear optimization problems using the Simplex method. The code showcases how to define objectives, constraints (inequalities/restrictions), and then solve for optimal solutions with sensitivity analysis. It also includes support for dual variables and intervals derived from inequalities.
-
Goal.java
Defines the optimization direction:MAXfor maximization orMINfor minimization. -
Inequality.java
Represents a single linear inequality of the form:(coeff1 * var1 + coeff2 * var2 + ... ) >= constantInternally, it stores the variables, their coefficients, and a constant term. The
toString()method formats the inequality for readable output. -
InequalitySolver.java
Given a set of inequalities and focusing on one variable (with others assumed zero),InequalitySolverdetermines the feasible interval of that variable. It returns either a valid interval ornullif no feasible solution exists. -
Main.java
The entry point of the application. Here, you can:- Define decision variables.
- Set up the objective function (with its coefficients and optimization direction).
- Create constraints as
Restrictionobjects. - Run the Simplex solver and perform sensitivity analysis.
Change the commented sections to test different problem instances.
-
ObjectiveFunction.java
Specifies the objective function of the optimization problem. It sets whether to maximize or minimize a linear expression given by variable coefficients. This is used when constructing the Simplex tableau. -
Quadruple.java
A simple record-like structure to store four related values. -
Relation.java
Enumerates the type of constraint relation:EQUAL,LESS_THAN_EQUAL, orGREATER_THAN_EQUAL. -
Restriction.java
Defines a single constraint (or “restriction”) in the linear problem. It holds:- A unique ID
- A relation type (
=,<=,>=) - Right-hand side value (RHS)
- Lists of variables and their coefficients
This class also handles adding slack, surplus, and artificial variables as needed for the Simplex method.
-
Simplex.java
Implements the core Simplex algorithm steps:- Converts the given problem into a Simplex tableau.
- Iteratively performs pivot operations to move towards the optimal solution.
- Prints intermediate tableaus and final solutions.
- Performs sensitivity analysis on constraints and resources once the optimal solution is found.
-
Tuple.java
A simple record-like structure to store a pair of values. -
Util.java
Utility functions for:- Checking uniqueness of variables.
- Sorting variables in a consistent order.
- Handling substitutions and solving simplified inequalities for dual analysis.
To run the code, open a Java environment (such as an IDE or command line), ensure the files are in a proper package and directory structure if needed, and run the Main.java file. You can adjust the defined variables, objective function, and constraints in Main.java to test different linear optimization scenarios.
- Formulating a Linear Program (LP): How to represent decision variables, the objective function, and constraints.
- Solving with Simplex: How to convert an LP into a tableau and use pivoting rules to reach an optimal solution.
- Reading Results and Sensitivity Analysis: Once an optimal solution is found, how to interpret dual variables, price ranges, and feasibility intervals.
This code is primarily for demonstration and instructional purposes. For production use, consider more robust implementations or libraries.