<commit_before>#include <cstdlib>
#include <iostream>
#include <limits>
#include <vector>
#include "gomory.h"

Gomory::Gomory(const rapidjson::Value& root, std::string model_path_,
               std::string solution_path_) : BaseModel(root, model_path_,
                                                       solution_path_) {
	// Load required user-defined parameters.
	max_cuts = root["maxCuts"].GetInt();
	away_epsilon = root["awayEpsilon"].GetDouble();
	purge_epsilon = root["purgeEpsilon"].GetDouble();
	use_lex = root["useLexicographic"].GetBool();
	use_rounds = root["useRounds"].GetBool();
	use_fgmi = root["useMixedCut"].GetBool();
	use_purging = root["usePurging"].GetBool();

	// Set up the Gurobi environment variable.
	grb_error = GRBloadenv(&env, "gurobi.log");

	// Ensure Gurobi behaves only as a very accurate linear programming solver.
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_BARCONVTOL, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_FEASIBILITYTOL, 1.0e-9);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_HEURISTICS, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_MARKOWITZTOL, 0.999);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_NODELIMIT, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_OPTIMALITYTOL, 1.0e-9);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_CUTS, 0);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_PRESOLVE, 0);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_QUAD, 1);

	// Turn off Gurobi shell output.
	grb_error = GRBsetintparam(env, GRB_INT_PAR_OUTPUTFLAG, 0);

	// Set the timeout option.
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_TIMELIMIT, 60.0);

	// Read in the mixed-integer model.
	grb_error = GRBreadmodel(env, model_path.c_str(), &model);

	// Convert the read-in model to a linear program.
	SetupModel();
}

void Gomory::Optimize(void) {
	grb_error = GRBoptimize(model);

	int model_status;
	grb_error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &model_status);

	if (model_status != 2) {
		std::cout << INT_MAX << "," << INT_MAX << "," << INT_MAX << "," << INT_MAX << std::endl;
		std::exit(model_status);
	}
}

void Gomory::LexSimplex(void) {
	grb_error = GRBgetintattr(model, "NumConstrs", &num_constrs);

	double sol_i;
	grb_error = GRBgetdblattrelement(model, "X", 0, &sol_i);

	int id[1] = {0};
	double vid[1] = {1.0};
	grb_error = GRBaddconstr(model, 1, id, vid, GRB_EQUAL, sol_i, NULL);
	del_lex_constr_ids[0] = num_constrs;

	for (int j = 1; j < num_vars; j++) {
		for (int k = 0; k < num_vars; k++) {
			if (k == j) {
				grb_error = GRBsetdblattrelement(model, GRB_DBL_ATTR_OBJ, k, -1.0);
			} else {
				grb_error = GRBsetdblattrelement(model, GRB_DBL_ATTR_OBJ, k, 0.0);
			}
		}

		Optimize();

		int id[1] = {j};
		double vid[1] = {1.0};

		double sol_j;
		grb_error = GRBgetdblattrelement(model, "X", j, &sol_j);
		grb_error = GRBaddconstr(model, 1, id, vid, GRB_EQUAL, sol_j, NULL);
		del_lex_constr_ids[j] = num_constrs + j;
	}

	Optimize();
<commit_msg>Err... maybe this fixes it?<commit_after>#include <cstdlib>
#include <iostream>
#include <limits>
#include <vector>
#include "gomory.h"

Gomory::Gomory(const rapidjson::Value& root, std::string model_path_,
               std::string solution_path_) : BaseModel(root, model_path_,
                                                       solution_path_) {
	// Load required user-defined parameters.
	max_cuts = root["maxCuts"].GetInt();
	away_epsilon = root["awayEpsilon"].GetDouble();
	purge_epsilon = root["purgeEpsilon"].GetDouble();
	use_lex = root["useLexicographic"].GetBool();
	use_rounds = root["useRounds"].GetBool();
	use_fgmi = root["useMixedCut"].GetBool();
	use_purging = root["usePurging"].GetBool();

	// Set up the Gurobi environment variable.
	grb_error = GRBloadenv(&env, "gurobi.log");

	// Ensure Gurobi behaves only as a very accurate linear programming solver.
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_BARCONVTOL, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_FEASIBILITYTOL, 1.0e-9);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_HEURISTICS, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_MARKOWITZTOL, 0.999);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_NODELIMIT, 0.0);
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_OPTIMALITYTOL, 1.0e-9);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_CUTS, 0);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_PRESOLVE, 0);
	grb_error = GRBsetintparam(env, GRB_INT_PAR_QUAD, 1);

	// Turn off Gurobi shell output.
	grb_error = GRBsetintparam(env, GRB_INT_PAR_OUTPUTFLAG, 0);

	// Set the timeout option.
	grb_error = GRBsetdblparam(env, GRB_DBL_PAR_TIMELIMIT, 60.0);

	// Read in the mixed-integer model.
	grb_error = GRBreadmodel(env, model_path.c_str(), &model);

	// Convert the read-in model to a linear program.
	SetupModel();
}

void Gomory::Optimize(void) {
	grb_error = GRBoptimize(model);

	int model_status;
	grb_error = GRBgetintattr(model, GRB_INT_ATTR_STATUS, &model_status);

	if (model_status != 2) {
		std::cout << INT_MAX << "," << INT_MAX << "," << INT_MAX << "," << INT_MAX << std::endl;
		std::exit(model_status);
	}
}

void Gomory::LexSimplex(void) {
	grb_error = GRBgetintattr(model, "NumConstrs", &num_constrs);

	double sol_i;
	grb_error = GRBgetdblattrelement(model, "X", 0, &sol_i);

	int id[1] = {0};
	double vid[1] = {1.0};
	grb_error = GRBaddconstr(model, 1, id, vid, GRB_EQUAL, sol_i, NULL);
	del_lex_constr_ids[0] = num_constrs;

	for (int j = 1; j < num_vars; j++) {
		for (int k = 0; k < num_vars; k++) {
			if (k == j) {
				grb_error = GRBsetdblattrelement(model, GRB_DBL_ATTR_OBJ, k, original_obj_coeffs[j]);
			} else {
				grb_error = GRBsetdblattrelement(model, GRB_DBL_ATTR_OBJ, k, 0.0);
			}
		}

		Optimize();

		int id[1] = {j};
		double vid[1] = {1.0};

		double sol_j;
		grb_error = GRBgetdblattrelement(model, "X", j, &sol_j);
		grb_error = GRBaddconstr(model, 1, id, vid, GRB_EQUAL, sol_j, NULL);
		del_lex_constr_ids[j] = num_constrs + j;
	}

	Optimize();

{'fraction_non_alphanumeric': 0.14426007450050796, 'fraction_numerical': 0.014222824246528954, 'mean_word_length': 4.583175803402646, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '215809', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2447, 'n_words': 468}