<commit_before>package cspfj;

import java.io.IOException;
import java.util.logging.Logger;

import cspfj.exception.MaxBacktracksExceededException;
import cspfj.heuristic.Heuristic;
import cspfj.problem.Problem;
import cspfj.problem.Variable;

public class Combo extends AbstractSolver {

	private final AbstractLocalSolver mCSolver;

	private final MGAC macSolver;

	private final Heuristic heuristic;

	private final static Logger logger = Logger
			.getLogger("cspfj.solver.ComboSolver");

	private float localTime = -1;

	// private final NoGoodManager noGoodManager;

	public Combo(Problem prob, ResultHandler resultHandler,
			Heuristic heuristic, boolean reverse) {
		super(prob, resultHandler);
		macSolver = new MGAC(prob, resultHandler, heuristic, reverse);
		mCSolver = new WMC(prob, resultHandler);
		this.heuristic = heuristic;

	}

	public boolean runSolver() throws IOException {
		System.gc();

		if (!preprocess(macSolver.getFilter())) {
			return false ;
		}

		// final int localBT = (int) (-500 + 8.25 * problem.getMaxDomainSize()
		// * problem.getNbVariables() + 0.24 * Math.pow(problem
		// .getMaxDomainSize()
		// * problem.getNbVariables(), 2));

		heuristic.compute();

		final int localBT = 2000;

		int maxBT = localBT/10;

		final float endLocalTime = chronometer.getCurrentChrono() + localTime;
		logger.info("It is " + chronometer.getCurrentChrono()
				+ ", local search until " + endLocalTime);
		// boolean alt = false;

//		final Map<Integer, Integer> weights = new HashMap<Integer, Integer>();

		while (chronometer.getCurrentChrono() < endLocalTime) {
			logger.info(localBT + " flips");
			float localTime = -chronometer.getCurrentChrono();
			int assign = -this.getNbAssignments();

			if (minConflicts(localBT)) {
				return true;
			}

			for (Variable v : problem.getVariables()) {
				v.resetAssign();
			}

			problem.restoreAll(1);

			localTime += chronometer.getCurrentChrono();
			assign += getNbAssignments();
			logger.info("Took " + localTime + " s (" + (localBT / localTime)
					+ " flips per second), " + assign + " assignments made");

//			 int maxWeight = 0 ;
//			
//			for (Constraint c : problem.getConstraints()) {
//				final int cid = c.getId();
//				final int weight;
//				if (weights.containsKey(cid)) {
//					weight = weights.get(cid) + c.getWeight();
//				} else {
//					weight = c.getWeight();
//				}
//				if (weight > maxWeight) { maxWeight = weight ; }
//				weights.put(cid, weight);
//				c.setWeight(1);
//			}
//			logger.info("Global max weight : " + maxWeight) ;
		}

		statistics("local-assign", mCSolver.getNbAssignments());
		
		

		do {
			logger.info("MAC with " + maxBT + " bt");
			int assign = -getNbAssignments();
			float macTime = -chronometer.getCurrentChrono();
			if (mac(maxBT)) {
				statistics("mac-assign", macSolver.getNbAssignments());
				return getNbSolutions() > 0;
			}

			problem.restoreAll(1);
			macTime += chronometer.getCurrentChrono();
			assign += getNbAssignments();
			logger.info("Took " + macTime + " s (" + (maxBT / macTime)
					+ " bt per second), " + assign + " assignments made");

			maxBT *= 1.5;
		} while (true);

	}

	private final boolean mac(final int maxBT) {
		macSolver.setMaxBacktracks(maxBT);

		try {
			if (macSolver.mac(0, null)) {<commit_msg>*** empty log message ***<commit_after>package cspfj;

import java.io.IOException;
import java.util.logging.Logger;

import cspfj.exception.MaxBacktracksExceededException;
import cspfj.heuristic.Heuristic;
import cspfj.problem.Problem;
import cspfj.problem.Variable;

public class Combo extends AbstractSolver {

	private final AbstractLocalSolver mCSolver;

	private final MGAC macSolver;

	private final Heuristic heuristic;

	private final static Logger logger = Logger
			.getLogger("cspfj.solver.ComboSolver");

	private float localTime = -1;

	// private final NoGoodManager noGoodManager;

	public Combo(Problem prob, ResultHandler resultHandler,
			Heuristic heuristic, boolean reverse) {
		super(prob, resultHandler);
		macSolver = new MGAC(prob, resultHandler, heuristic, reverse);
		mCSolver = new WMC(prob, resultHandler);
		this.heuristic = heuristic;

	}

	public boolean runSolver() throws IOException {
		System.gc();

		if (!preprocess(macSolver.getFilter())) {
			return false;
		}

		// final int localBT = (int) (-500 + 8.25 * problem.getMaxDomainSize()
		// * problem.getNbVariables() + 0.24 * Math.pow(problem
		// .getMaxDomainSize()
		// * problem.getNbVariables(), 2));

		heuristic.compute();

		final int localBT = 2000;

		int maxBT = localBT / 10;

		float maxTries = 1;
		// boolean alt = false;

		// final Map<Integer, Integer> weights = new HashMap<Integer,
		// Integer>();

		do {
			float localTime = -chronometer.getCurrentChrono();
			for (int i = (int)Math.floor(maxTries); --i >= 0;) {
				logger.info(localBT + " flips");

				int assign = -this.getNbAssignments();

				if (minConflicts(localBT)) {
					return true;
				}

				for (Variable v : problem.getVariables()) {
					v.resetAssign();
				}

				problem.restoreAll(1);

				assign += getNbAssignments();
				
			}
			localTime += chronometer.getCurrentChrono();
			logger.info("Took " + localTime + " s");
			
			logger.info("MAC with " + maxBT + " bt");

			float macTime = -chronometer.getCurrentChrono();
			if (mac(maxBT)) {
				statistics("mac-assign", macSolver.getNbAssignments());
				return getNbSolutions() > 0;
			}

			problem.restoreAll(1);
			macTime += chronometer.getCurrentChrono();

			maxTries *= 1.5;
			maxBT *= 1.5 * localTime / macTime;
		} while (true);

	}

	private final boolean mac(final int maxBT) {
		macSolver.setMaxBacktracks(maxBT);

		try {
			if (macSolver.mac(0, null)) {
{'fraction_non_alphanumeric': 0.1370585134422773, 'fraction_numerical': 0.009137234229485152, 'mean_word_length': 3.5246422893481717, 'pattern_counts': {'":': 0, '<': 8, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '194663', 'n_tokens_mistral': 2216, 'n_tokens_neox': 1859, 'n_words': 429}