Added linear programming problem (lpp) module. Ready but untested.
[libfirm] / ir / be / lpp.h
1 /**
2  * Author:      Daniel Grund
3  * Date:                16.05.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  */
7
8 #include <stdio.h>
9
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, real=1, binary=2} var_t;
13
14 /**
15  * Fixed-column mps where spaces are allowed in identifiers :-0
16  * Free mps where whitespace is a seperator :-)
17  * LP format
18  */
19 typedef enum _style_t {s_mps_fixed, s_mps_free, s_lp} style_t;
20
21 typedef struct _lpp_t lpp_t;
22
23 /**
24  * Creates a new problem. Optimization type is minimize or maximize
25  */
26 lpp_t *new_lp(char *name, opt_t opt_type);
27
28 void free_lp(lpp_t *lpp);
29
30 /**
31  * Adds a constraint to a problem. If a constraint with the same name already exists result is undefined.
32  * @param cst_name The name of the constraint.
33  * @param cst_type The type of constraint: objective, equality, less-or-equal, greater-or-equal
34  */
35 void lpp_add_constr(lpp_t *lpp, const char *cst_name, cst_t cst_type);
36
37 /**
38  * Adds a variable to a problem. If a variable with the same name already exists result is undefined.
39  * @param var_name The name of the variable.
40  * @param var_type The type of the var: real or binary
41  * NOTE: common integer or semi-continous vars are not (yet) implemented
42  */
43 void lpp_add_var(lpp_t *lpp, const char *var_name, var_t var_type);
44
45 /**
46  * Sets the factor of the variable @p var_name in constraint @p cst_name to @p value.
47  */
48 void lpp_set_factor(lpp_t *lpp, const char *cst_name, const char *var_name, int value);
49
50 /**
51  * Sets the value for the right hand side of constraint @p cst_name to @p value
52  */
53 void lpp_set_rhs(lpp_t *lpp, char *cst_name, int value);
54
55 /**
56  * Sets, for constraint @p cst_name, all factors of all variables
57  * given in @p var_names to the values given in @p values.
58  */
59 void lpp_set_all_constr(lpp_t *lpp, char *cst_name, char **var_names, int *values);
60
61 /**
62  * Writes out the problem in the format specified be @p style.
63  */
64 void lpp_dump(lpp_t *lpp, FILE *out, style_t style);