3
parseLP.ts
bRNS98 edited this page 2024-10-11 23:23:38 +02:00

Documentation for parseLP.ts

This document provides a comprehensive overview of the TypeScript file parseLP.ts which contains the type definitions and functions used for handling Linear Programming (LP) problems.


Index

  1. Overview
  2. Type Definitions
  3. Functions

Overview

The parseLP.ts file is designed to define the structure of an LP problem and create instances of LP problems. It also includes a placeholder for a function to parse LP problem descriptions from a string input.

Type Definitions

VariableLP

This type is used to define a variable in a linear programming problem.

  • Attributes:
    • name: string - Represents the name of the variable.
    • coef: number - Represents the coefficient of the variable in the objective function or constraints.
type VariableLP = { 
  name: string; 
  coef: number; 
};

ConstraintLP

This type represents a constraint in a linear programming problem.

  • Attributes:
    • name: string - The name of the constraint.
    • vars: VariableLP[] - An array of VariableLP representing the variables involved in this constraint.
    • bnds: { ub: number; lb: number } - An object representing the bounds for the constraint.
      • ub: number - Upper bound of the constraint.
      • lb: number - Lower bound of the constraint.
type ConstraintLP = { 
  name: string; 
  vars: VariableLP[]; 
  bnds: { 
    ub: number; 
    lb: number; 
  }; 
};

ProblemLP

This interface represents an LP problem as a whole.

  • Attributes:
    • objective: { vars: VariableLP[]; } - An object containing an array of VariableLP for the objective function.
    • constraints: ConstraintLP[] - An array of ConstraintLP, representing the constraints of the LP problem.

```typescript# Documentation for parseLP.ts

This document provides a comprehensive overview of the TypeScript file parseLP.ts which contains the type definitions and functions used for handling Linear Programming (LP) problems. Linear Programming is a method to achieve the best outcome in a mathematical model whose requirements are represented by linear relationships.


Index

  1. Overview
  2. Type Definitions
  3. Functions
  4. Conclusion

Overview

The parseLP.ts file is designed to define the structure of an LP problem and create instances of LP problems. It also includes a placeholder for a function to parse LP problem descriptions from a string input.

Type Definitions

VariableLP

This type is used to define a variable in a linear programming problem.

  • Attributes:
    • name: string - Represents the name of the variable.
    • coef: number - Represents the coefficient of the variable in the objective function or constraints.
type VariableLP = { 
  name: string; 
  coef: number; 
};

ConstraintLP

This type represents a constraint in a linear programming problem.

  • Attributes:
    • name: string - The name of the constraint.
    • vars: VariableLP[] - An array of VariableLP representing the variables involved in this constraint.
    • bnds: { ub: number; lb: number } - An object representing the bounds for the constraint.
      • ub: number - Upper bound of the constraint.
      • lb: number - Lower bound of the constraint.
type ConstraintLP = { 
  name: string; 
  vars: VariableLP[]; 
  bnds: { 
    ub: number; 
    lb: number; 
  }; 
};

ProblemLP

This interface represents an LP problem as a whole.

  • Attributes:
    • objective: { vars: VariableLP[]; } - An object containing an array of VariableLP for the objective function.
    • constraints: ConstraintLP[] - An array of ConstraintLP, representing the constraints of the LP problem.
interface ProblemLP { 
  objective: { 
    vars: VariableLP[]; 
  }; 
  constraints: ConstraintLP[]; 
}

Functions

createProblemLP

This function is responsible for creating a ProblemLP from the provided objective variables and constraints.

  • Parameters:

    • objectiveVars: VariableLP[] - An array of variables for the objective function.
    • constraints: { name: string; vars: VariableLP[]; ub: number; lb: number }[] - An array of objects representing constraints.
  • Returns:

    • ProblemLP - An object that represents the linear programming problem.
  • Functionality:

    • The function maps input constraints into the ConstraintLP format.
    • It then constructs an LP problem combining the formatted constraints and objective variables.
function createProblemLP(
  objectiveVars: VariableLP[], 
  constraints: { name: string; vars: VariableLP[]; ub: number; lb: number }[]
): ProblemLP {
  const constraintsFormatted: ConstraintLP[] = constraints.map((constraint) => ({
    name: constraint.name,
    vars: constraint.vars,
    bnds: { ub: constraint.ub, lb: constraint.lb }
  }));

  const problem: ProblemLP = { 
    objective: { vars: objectiveVars }, 
    constraints: constraintsFormatted 
  };

  return problem;
}

parseLP

The parseLP function is a placeholder meant to parse a linear programming problem from a string input.

  • Parameters:

    • input: string - The string representation of an LP problem.
  • Functionality:

    • Currently, it logs the input string to the console with a message indicating that an LP file is being parsed.
export function parseLP(input: string) {
  console.log("Parsing LP file:", input);
}

Conclusion

The parseLP.ts file provides a structured approach to defining and creating linear programming problems in TypeScript. By defining specific types and a function for problem creation, it lays the groundwork for handling LP models efficiently. The parseLP function is set to be developed further to enable parsing from string inputs, enhancing its utility. interface ProblemLP { objective: { vars: VariableLP[]; }; constraints: ConstraintLP[]; }


## Functions

### `createProblemLP`

This function is responsible for creating a `ProblemLP` from the provided objective variables and constraints.

- **Parameters:**
  - `objectiveVars: VariableLP[]` - An array of variables for the objective function.
  - `constraints: { name: string; vars: VariableLP[]; ub: number; lb: number }[]` - An array of objects representing constraints.

- **Returns:**
  - `ProblemLP` - An object that represents the linear programming problem.

- **Functionality:**
  - The function maps input constraints into the `ConstraintLP` format.
  - It then constructs an `LP` problem combining the formatted constraints and objective variables.

```typescript
function createProblemLP(
  objectiveVars: VariableLP[], 
  constraints: { name: string; vars: VariableLP[]; ub: number; lb: number }[]
): ProblemLP {
  const constraintsFormatted: ConstraintLP[] = constraints.map((constraint) => ({
    name: constraint.name,
    vars: constraint.vars,
    bnds: { ub: constraint.ub, lb: constraint.lb }
  }));

  const problem: ProblemLP = { 
    objective: { vars: objectiveVars }, 
    constraints: constraintsFormatted 
  };

  return problem;
}

parseLP

The parseLP function is a placeholder meant to parse a linear programming problem from a string input.

  • Parameters:

    • input: string - The string representation of an LP problem.
  • Functionality:

    • Currently, it logs the input string to the console with a message indicating that an LP file is being parsed.
export function parseLP(input: string) {
  console.log("Parsing LP file:", input);
}