Created parseMIP.ts (markdown)

bRNS98
2024-10-11 23:24:58 +02:00
parent 07a4c1de72
commit 10ee33123b
+129
@@ -0,0 +1,129 @@
# Documentation for `parseMIP.ts`
## Overview
The `parseMIP.ts` file is a TypeScript module that defines interfaces and functions for handling Mixed Integer Programming (MIP) problems. This module is designed to create and parse MIP problems, which are optimization problems that involve both continuous and integer variables. The code provides a structured way to define the problem components such as variables, constraints, and options, and encapsulates these components into a `Problem` object.
## Index
1. [Interfaces](#interfaces)
- [VariableMIP](#variablemip)
- [Bounds](#bounds)
- [ConstraintMIP](#constraintmip)
- [Options](#options)
- [Problem](#problem)
2. [Functions](#functions)
- [createProblemMIP](#createproblemmip)
- [parseLP](#parselp)
## Interfaces
### VariableMIP
The `VariableMIP` interface defines a structure for representing a variable in the MIP problem.
| **Property** | **Type** | **Description** |
|--------------|----------|------------------------------------|
| `name` | `string` | Name of the variable. |
| `coef` | `number` | Coefficient of the variable. |
### Bounds
The `Bounds` interface specifies the bounds for a constraint in the MIP problem.
| **Property** | **Type** | **Description** |
|--------------|----------|-------------------------------------|
| `type` | `number` | Type of the bound (e.g., <=, >=, =).|
| `ub` | `number` | Upper bound for the constraint. |
| `lb` | `number` | Lower bound for the constraint. |
### ConstraintMIP
The `ConstraintMIP` interface outlines the structure for constraints within the MIP problem.
| **Property** | **Type** | **Description** |
|--------------|------------------|-----------------------------------|
| `name` | `string` | Name of the constraint. |
| `vars` | `VariableMIP[]` | Array of variables in the constraint.|
| `bnds` | `Bounds` | Bounds for the constraint. |
### Options
The `Options` interface defines additional parameters for solving the MIP problem.
| **Property** | **Type** | **Description** |
|--------------|----------|-------------------------------------|
| `mipgap` | `number` | MIP gap tolerance. |
| `tmlim` | `number` | Time limit for solving the problem. |
| `msglev` | `number` | Message level for output verbosity. |
### Problem
The `Problem` interface represents an entire MIP problem, encompassing all components such as objective, constraints, and options.
| **Property** | **Type** | **Description** |
|------------------|-------------------------|-------------------------------------|
| `name` | `string` | Name of the problem. |
| `objective` | `object` | Objective function details. |
| `constraints` | `ConstraintMIP[]` | Array of constraints. |
| `binaries` | `string[]` (optional) | List of binary variables. |
| `generals` | `string[]` (optional) | List of general integer variables. |
| `options` | `Options` | Solver options. |
## Functions
### createProblemMIP
The **`createProblemMIP`** function constructs a `Problem` object by accepting parameters that define the problem's name, objective, constraints, and options.
#### Parameters
- **`name: string`**: The name of the MIP problem.
- **`direction: "min" | "max"`**: The direction of optimization (minimize or maximize).
- **`objectiveName: string`**: The name of the objective function.
- **`objectiveVars: VariableMIP[]`**: Variables involved in the objective function.
- **`constraints: { name: string; vars: VariableMIP[]; bnds_type: number; ub: number; lb: number }[]`**: Array of constraints details.
- **`binaries: string[]`**: Array of binary variables.
- **`generals: string[]` (optional)**: Array of general integer variables.
- **`mipgap: number`**: MIP gap tolerance.
- **`tmlim: number`**: Time limit for solving the problem.
- **`msglev: number`**: Message level for verbosity.
#### Returns
- **`Problem`**: A structured representation of the MIP problem.
#### Example
```typescript
const problem = createProblemMIP(
"SampleProblem",
"min",
"ObjectiveFunction",
[{ name: "x1", coef: 1 }, { name: "x2", coef: 2 }],
[
{ name: "Constraint1", vars: [{ name: "x1", coef: 1 }], bnds_type: 1, ub: 10, lb: 0 }
],
["x1"],
["x2"],
0.01,
1000,
1
);
```
### parseLP
The **`parseLP`** function is designed to process and parse an input string representing a Linear Programming file (though named as `parseLP`, it prints a simple message for demonstration purposes).
#### Parameters
- **`input: string`**: The input string representing the LP file to be parsed.
#### Example
```typescript
parseLP("ExampleInputString");
```
This function currently logs the message `"Parsing MIP file:"` followed by the input string, indicating the start of a parsing process.