4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
10 typedef enum _opt_t {minimize, maximize} opt_t;
11 typedef enum _cst_t {objective=0, equal=1, less=2, greater=3} cst_t;
12 typedef enum _var_t {invalid=0, rhs=1, real=2, binary=3} var_t;
13 typedef enum _sol_state_t {unknown=0, no_solution_file=1, infeasible=2, unbounded=3, feasible=4, optimal=5} sol_state_t;
14 typedef struct _lpp_t lpp_t;
16 #define ERR_NAME_NOT_ALLOWED -2
19 * Creates a new problem. Optimization type is minimize or maximize.
20 * Implicit row with name "obj" is inserted.
21 * Implicit col with name "rhs" is inserted.
23 lpp_t *new_lpp(const char *name, opt_t opt_type);
25 void free_lpp(lpp_t *lpp);
28 * Adds a constraint to a problem. If a constraint with the same name already
29 * exists nothing is altered, and the index of the existing entry is returned.
30 * @param cst_name The name of the constraint (1st char only alpha-numeric!). If NULL, a default name will be used.
31 * @param cst_type The type of constraint: objective, equality, less-or-equal, greater-or-equal
32 * @param rhs The right hand side value to set for this constraint.
33 * @return The (new or existing) index of the constraint
35 int lpp_add_cst(lpp_t *lpp, const char *cst_name, cst_t cst_type, double rhs);
38 * Returns the internal index of a constraint.
39 * @param cst_name The name of the constraint
40 * @return The internal index of constraint @p cst_name or -1 if it does not exist.
42 int lpp_get_cst_idx(lpp_t *lpp, char *cst_name);
45 * Returns the name of a constraint.
46 * @param index The internal index of a constraint.
48 const char *lpp_get_cst_name(lpp_t *lpp, int index);
51 * Adds a variable to a problem. If a variable with the same name already
52 * exists nothing is altered, and the index of the existing entry is returned.
53 * @param var_name The name of the constraint (1st char only alpha-numeric!). If NULL, a default name will be used.
54 * @param var_type The type of variable: real, binary
55 * @param obj The objactive value coefficient for this variable.
56 * @return The (new or existing) index of the variable
58 * NOTE: common integer or semi-continous vars are not (yet) implemented
60 int lpp_add_var(lpp_t *lpp, const char *var_name, var_t var_type, double obj);
63 * Returns the internal index of a variable.
64 * @param cst_name The name of the variable
65 * @return The internal index of variable @p var_name or -1 if it does not exist.
67 int lpp_get_var_idx(lpp_t *lpp, char *var_name);
70 * Returns the name of a variable.
71 * @param index The internal index of a variable.
73 const char *lpp_get_var_name(lpp_t *lpp, int index);
76 * Sets the factor of the variable @p var_name in constraint @p cst_name to @p value.
77 * Use "obj" as constraint name to set factors in the objective function.
78 * Use "rhs" as variable name to set the right hand side values.
79 * @return -1 if constraint or variable name does not exist.
82 int lpp_set_factor(lpp_t *lpp, char *cst_name, char *var_name, double value);
85 * Same as lpp_set_factor but uses the internal indices instead of names.
86 * "obj" and "rhs" both have index 0.
87 * @return -1 if an index was invalid
90 int lpp_set_factor_fast(lpp_t *lpp, int cst_idx, int var_idx, double value);
93 * Set a starting value for a var.
94 * @param var_idx The index of the variable to set the value for.
95 * @param value The value to set.
97 void lpp_set_start_value(lpp_t *lpp, int var_idx, double value);
101 * @return -1 if an error ocurred, 0 otherwise
103 int lpp_solve(lpp_t *lpp, int use_start_values);
106 * @return The solution values of the variables from index begin to index end.
108 sol_state_t lpp_get_solution(lpp_t *lpp, double *values, int begin, int end);