<commit_before>/**
 * Author:      <NAME>
 * Date:		Fri 13.05.2005
 * Copyright:   (c) Universitaet Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "debug.h"
#include "lpp.h"
#include "xmalloc.h"
#include "assert.h"
#include "hashptr.h"
#include "set.h"
#include "sp_matrix.h"

/* CPLEX-account related stuff */
#undef DELETE_FILES		/**< deletes all dumped files after use. Files on server are always deleted. */
#define SSH_USER_HOST "<EMAIL>"
#define SSH_PASSWD_FILE "/ben/daniel/.smppw"
#define EXPECT_FILENAME "runme" /* name of the expect-script */

typedef struct _name_t name_t;
typedef enum _value_kind_t {none=0, start, solution} value_kind_t;

#define DEBUG_LVL SET_LEVEL_1
static firm_dbg_module_t *dbg = NULL;


struct _name_t {
	char *name;					/**< the name of the var/constraint supplied by user */
	int nr;						/**< the col/row number in the matrix */
	value_kind_t value_kind;
	double value;
	union _type {
		var_t var_type;
		cst_t cst_type;
	} type;
};

struct _lpp_t {
	/* The problem data */
	char *name;						/**< A textual name for this problem */
	opt_t opt_type;					/**< Optimization direction */
	sp_matrix_t *m;					/**< The matrix holding objective, constraints and rhs */

	/* Cst/Var to Nr mapping */
	set *cst2nr;					/**< Holds name_t's for constraints */
	set *var2nr;					/**< Holds name_t's for variables */

	/* Nr to Cst/Var mapping */
	int cst_size, var_size;			/**< Size of the csts/vars-arrays below */
	int cst_next, var_next;			/**< Next free position in arrays below */
	name_t **csts;					/**< Pointers to the elements in the cst2nr set */
	name_t **vars;					/**< Pointers to the elements in the var2nr set */

	/* Solution stuff */
	char *error;
	sol_state_t sol_state;
	double sol_time;
	unsigned iterations;

	unsigned next_name_number;
};

#define HASH_NAME_T(n) HASH_STR((n)->name, strlen((n)->name))

static INLINE FILE *ffopen(const char *base, const char *ext, const char *mode) {
	FILE *out;
	char buf[1024];

	snprintf(buf, sizeof(buf), "%s.%s", base, ext);
	if (! (out = fopen(buf, mode))) {
		fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode);
		return NULL;
	}
	return out;
}

static int cmp_name_t(const void *x, const void *y, size_t size) {
	const name_t *n = x;
	const name_t *m = y;
	return strcmp(n->name, m->name);
}

#define INITIAL_SIZE 64

lpp_t *new_lpp(const char *name, opt_t opt_type) {
	dbg = firm_dbg_register("ir.be.copyoptilp");
	firm_dbg_set_mask(dbg, DEBUG_LVL);

	lpp_t *lpp = xcalloc(1, sizeof(*lpp));
	lpp->name = xstrdup(name);
	lpp->opt_type = opt_type;
	lpp->cst2nr = new_set(cmp_name_t, INITIAL_SIZE);
	lpp->var2nr = new_set(cmp_name_t, INITIAL_SIZE);
	lpp->cst_size = INITIAL_SIZE;
	lpp->var_size = INITIAL_SIZE;
	lpp->csts = xcalloc(INITIAL_SIZE, sizeof(*lpp->csts));
	lpp->vars = xcalloc(INITIAL_SIZE, sizeof(*lpp->vars));
	lpp->m = new_matrix(INITIAL_SIZE, INITIAL_SIZE);
	lpp_add_cst(lpp, "obj", objective, 0);
	lpp_add_var(lpp, "rhs", rhs, 0);
	return lpp;
}

void free_lpp(lpp_t *lpp) {
	int i;
	for(i=0;i<lpp->cst_next;++i)
		free(lpp->csts[i]->name);
	for(i=0;i<lpp->var_next;++i)
		free(lpp->vars[i]->name);<commit_msg>added config.h removed C99 feature<commit_after>/**
 * Author:      <NAME>
 * Date:		Fri 13.05.2005
 * Copyright:   (c) Universitaet Karlsruhe
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_IO_H
#include <io.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "debug.h"
#include "lpp.h"
#include "xmalloc.h"
#include "assert.h"
#include "hashptr.h"
#include "set.h"
#include "sp_matrix.h"

/* CPLEX-account related stuff */
#undef DELETE_FILES		/**< deletes all dumped files after use. Files on server are always deleted. */
#define SSH_USER_HOST "<EMAIL>"
#define SSH_PASSWD_FILE <PASSWORD>"
#define EXPECT_FILENAME "runme" /* name of the expect-script */

typedef struct _name_t name_t;
typedef enum _value_kind_t {none=0, start, solution} value_kind_t;

#define DEBUG_LVL SET_LEVEL_1
static firm_dbg_module_t *dbg = NULL;


struct _name_t {
	char *name;					/**< the name of the var/constraint supplied by user */
	int nr;						/**< the col/row number in the matrix */
	value_kind_t value_kind;
	double value;
	union _type {
		var_t var_type;
		cst_t cst_type;
	} type;
};

struct _lpp_t {
	/* The problem data */
	char *name;						/**< A textual name for this problem */
	opt_t opt_type;					/**< Optimization direction */
	sp_matrix_t *m;					/**< The matrix holding objective, constraints and rhs */

	/* Cst/Var to Nr mapping */
	set *cst2nr;					/**< Holds name_t's for constraints */
	set *var2nr;					/**< Holds name_t's for variables */

	/* Nr to Cst/Var mapping */
	int cst_size, var_size;			/**< Size of the csts/vars-arrays below */
	int cst_next, var_next;			/**< Next free position in arrays below */
	name_t **csts;					/**< Pointers to the elements in the cst2nr set */
	name_t **vars;					/**< Pointers to the elements in the var2nr set */

	/* Solution stuff */
	char *error;
	sol_state_t sol_state;
	double sol_time;
	unsigned iterations;

	unsigned next_name_number;
};

#define HASH_NAME_T(n) HASH_STR((n)->name, strlen((n)->name))

static INLINE FILE *ffopen(const char *base, const char *ext, const char *mode) {
	FILE *out;
	char buf[1024];

	snprintf(buf, sizeof(buf), "%s.%s", base, ext);
	if (! (out = fopen(buf, mode))) {
		fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode);
		return NULL;
	}
	return out;
}

static int cmp_name_t(const void *x, const void *y, size_t size) {
	const name_t *n = x;
	const name_t *m = y;
	return strcmp(n->name, m->name);
}

#define INITIAL_SIZE 64

lpp_t *new_lpp(const char *name, opt_t opt_type) {
	lpp_t *lpp;

	dbg = firm_dbg_register("ir.be.copyoptilp");
	firm_dbg_set_mask(dbg, DEBUG_LVL);

	lpp = xcalloc(1, sizeof(*lpp));
	lpp->name = xstrdup(name);
	lpp->opt_type = opt_type;
	lpp->cst2nr = new_set(cmp_name_t, INITIAL_SIZE);
	lpp->var2nr = new_set(cmp_name_t, INITIAL_SIZE);
	lpp->cst_size = INITIAL_SIZE;
	lpp->var_size = INITIAL_SIZE;
	lpp->csts = xcalloc(INITIAL_SIZE, sizeof(*lpp->csts));
	lpp->vars = xcalloc(INITIAL_SIZE, sizeof(*lpp->vars));
	lpp->m = new_matrix(INITIAL_SIZE, INITIAL_SIZE);
	lpp_add_cst(lpp, "obj", objective, 0);
	lpp_add_var(lpp, "rhs", rhs, 0);
	return lpp;
}

void free_lpp(lpp_t *lpp) {
	int i;
	for(i=0;i<lpp->cst_next;++i)
		free(lpp->csts[i]->name);
	for(i=0;i<lpp->var_next;++i)
		free(lpp->vars[i]->name);
{'fraction_non_alphanumeric': 0.14994044073853485, 'fraction_numerical': 0.008338296605122097, 'mean_word_length': 4.057981927710843, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6465064', 'n_tokens_mistral': 2860, 'n_tokens_neox': 2699, 'n_words': 702}