-/**
- * Author: Daniel Grund
- * Date: Fri 13.05.2005
- * Copyright: (c) Universitaet Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- * CVS-Id: $Id: lpp.c 27353 2010-04-07 13:33:16Z matze $
+/*
+ * Copyright (C) 2005-2011 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
*/
+/**
+ * @file
+ * @author Daniel Grund
+ */
#include "config.h"
#include <stdlib.h>
#include "hashptr.h"
#include "debug.h"
#include "set.h"
+#include "debug.h"
#include "sp_matrix.h"
#include "mps.h"
#include "lpp_solvers.h"
#include "lpp_net.h"
-#define HASH_NAME_T(n) HASH_STR((n)->name, strlen((n)->name))
+#define HASH_NAME_T(n) hash_str((n)->name)
-static firm_dbg_module_t *dbg = NULL;
+DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
static inline char *obst_xstrdup(struct obstack *obst, const char *str)
{
{
const lpp_name_t *n = x;
const lpp_name_t *m = y;
- (void)size; /* stop warnings */
+ (void)size;
return strcmp(n->name, m->name);
}
lpp->density = (double)lpp->n_elems / (double)(lpp->cst_next * lpp->var_next) * 100.0;
}
-#define INITIAL_SIZE 64
-
-lpp_t *new_lpp(const char *name, lpp_opt_t opt_type)
+lpp_t *lpp_new(const char *name, lpp_opt_t opt_type)
{
- return new_lpp_userdef(name, opt_type, INITIAL_SIZE, INITIAL_SIZE, 2.0);
+ return lpp_new_userdef(name, opt_type, 64, 64, 2.0);
}
-lpp_t *new_lpp_userdef(const char *name, lpp_opt_t opt_type,
- int estimated_vars, int estimated_csts, double grow_factor)
+lpp_t *lpp_new_userdef(const char *name, lpp_opt_t opt_type,
+ int estimated_vars, int estimated_csts,
+ double grow_factor)
{
lpp_t *lpp;
int idx;
- dbg = firm_dbg_register("lpp");
+ DEBUG_ONLY(dbg = firm_dbg_register("lpp");)
lpp = XMALLOCZ(lpp_t);
obstack_init(&lpp->obst);
return lpp;
}
-void free_lpp_matrix(lpp_t *lpp)
+void lpp_free_matrix(lpp_t *lpp)
{
del_matrix(lpp->m);
lpp->m = NULL;
}
-void free_lpp(lpp_t *lpp)
+void lpp_free(lpp_t *lpp)
{
obstack_free(&lpp->obst, NULL);
matrix_set(lpp->m, 0, 0, value);
}
-static inline int name2nr(set *where, const char *name)
+static int name2nr(set *where, const char *name)
{
lpp_name_t find, *found;
find.name = name;
return (found ? found->nr : -1);
}
-#define cst_nr(lpp, name) name2nr(lpp->cst2nr, name)
-#define var_nr(lpp, name) name2nr(lpp->var2nr, name)
+static int cst_nr(const lpp_t *lpp, const char *name)
+{
+ return name2nr(lpp->cst2nr, name);
+}
+
+static int var_nr(const lpp_t *lpp, const char *name)
+{
+ return name2nr(lpp->var2nr, name);
+}
static inline char *get_next_name(lpp_t *lpp)
{
fprintf(stderr, "constraint %s unsatisfied: %g != %g\n", cst->name, sum, cst_val);
}
break;
- case lpp_less:
+ case lpp_less_equal:
if(sum > cst_val) {
- fprintf(stderr, "constraint %s unsatisfied: %g > %g\n", cst->name, sum, cst_val);
+ fprintf(stderr, "constraint %s unsatisfied: %g >= %g\n", cst->name, sum, cst_val);
}
break;
- case lpp_greater:
+ case lpp_greater_equal:
if(sum < cst_val) {
- fprintf(stderr, "constraint %s unsatisfied: %g < %g\n", cst->name, sum, cst_val);
+ fprintf(stderr, "constraint %s unsatisfied: %g <= %g\n", cst->name, sum, cst_val);
}
break;
default:
switch(cst) {
case lpp_equal:
return "=";
- case lpp_less:
+ case lpp_less_equal:
return "<=";
- case lpp_greater:
+ case lpp_greater_equal:
return ">=";
default:
return "";
}
}
-#define NAMELEN 64
-
/**
* Deserialize an lpp from a file descriptor.
* @param comm The file descriptor.
if(with_names) {
name.name = lpp_reads(comm);
} else {
- char* buf = XMALLOCN(char, NAMELEN);
- snprintf(buf, NAMELEN, "c%d\n", name.nr);
+ char* buf = XMALLOCN(char, 32);
+ snprintf(buf, 32, "c%d\n", name.nr);
name.name = buf;
}
if(with_names) {
name.name = lpp_reads(comm);
} else {
- char* buf = XMALLOCN(char, NAMELEN);
- snprintf(buf, NAMELEN, "v%d\n", name.nr);
+ char* buf = XMALLOCN(char, 32);
+ snprintf(buf, 32, "v%d\n", name.nr);
name.name = buf;
}