<commit_before>package etomica;

/**
 * Integrator to perform Metropolis Monte Carlo sampling. Works with a set of
 * MCMove instances that are added to the integrator. A step performed by the
 * integrator consists of selecting a MCMove from the set, performing the trial
 * defined by the MCMove, and deciding acceptance of the trial using information
 * from the MCMove.
 * 
 * @author <NAME>
 */

public class IntegratorMC extends Integrator implements EtomicaElement {

	/**
	 * Constructs integrator and establishes PotentialMaster instance that
	 * will be used by moves to calculate the energy.
	 */
	public IntegratorMC(PotentialMaster potentialMaster) {
		super(potentialMaster);
		setIsothermal(true); //has no practical effect, but sets value of
		// isothermal to be consistent with way integrator
		// is sampling
	}

	public static EtomicaInfo getEtomicaInfo() {
		EtomicaInfo info = new EtomicaInfo("General Monte Carlo simulation");
		return info;
	}

	/**
	 * Sets moves in given array to be integrator's set of moves, deleting any
	 * existing moves.
	 */
	public void setMCMoves(MCMove[] moves) {
		firstMoveLink = null;
		moveCount = 0;
		for (int i = 0; i < moves.length; i++) {
			addMCMove(moves[i]);
		}
	}

	/**
	 * Constructs and returns array of all moves added to the integrator.
	 */
	public MCMove[] getMCMoves() {
		MCMove[] moves = new MCMove[moveCount];
		int i = 0;
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			moves[i++] = link.move;
		}
		return moves;
	}

	/**
	 * Adds the given MCMove to the set of moves performed by the integrator and
	 * recalculates move frequencies.
	 */
	public void addMCMove(MCMove move) {
		//make sure move wasn't added already
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			if (move == link.move)
				return;
		}
		if (firstMoveLink == null) {
			firstMoveLink = new MCMoveLinker(move);
		} else {
			lastMoveLink.nextLink = new MCMoveLinker(move);
			lastMoveLink = lastMoveLink.nextLink;
		}
		move.setPhase(phase);
		move.setTemperature(temperature);
		moveCount++;
		recomputeMoveFrequencies();
	}

	/**
	 * Invokes superclass method and informs all MCMoves about the new phase.
	 */
	public boolean addPhase(Phase p) {
		if (!super.addPhase(p))
			return false;
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			link.move.setPhase(phase);<commit_msg>set lastMoveLink in first call to addMCMove<commit_after>package etomica;

/**
 * Integrator to perform Metropolis Monte Carlo sampling. Works with a set of
 * MCMove instances that are added to the integrator. A step performed by the
 * integrator consists of selecting a MCMove from the set, performing the trial
 * defined by the MCMove, and deciding acceptance of the trial using information
 * from the MCMove.
 * 
 * @author <NAME>
 */

public class IntegratorMC extends Integrator implements EtomicaElement {

	/**
	 * Constructs integrator and establishes PotentialMaster instance that
	 * will be used by moves to calculate the energy.
	 */
	public IntegratorMC(PotentialMaster potentialMaster) {
		super(potentialMaster);
		setIsothermal(true); //has no practical effect, but sets value of
		// isothermal to be consistent with way integrator
		// is sampling
	}

	public static EtomicaInfo getEtomicaInfo() {
		EtomicaInfo info = new EtomicaInfo("General Monte Carlo simulation");
		return info;
	}

	/**
	 * Sets moves in given array to be integrator's set of moves, deleting any
	 * existing moves.
	 */
	public void setMCMoves(MCMove[] moves) {
		firstMoveLink = null;
		moveCount = 0;
		for (int i = 0; i < moves.length; i++) {
			addMCMove(moves[i]);
		}
	}

	/**
	 * Constructs and returns array of all moves added to the integrator.
	 */
	public MCMove[] getMCMoves() {
		MCMove[] moves = new MCMove[moveCount];
		int i = 0;
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			moves[i++] = link.move;
		}
		return moves;
	}

	/**
	 * Adds the given MCMove to the set of moves performed by the integrator and
	 * recalculates move frequencies.
	 */
	public void addMCMove(MCMove move) {
		//make sure move wasn't added already
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			if (move == link.move)
				return;
		}
		if (firstMoveLink == null) {
			firstMoveLink = new MCMoveLinker(move);
            lastMoveLink = firstMoveLink;
		} else {
			lastMoveLink.nextLink = new MCMoveLinker(move);
			lastMoveLink = lastMoveLink.nextLink;
		}
		move.setPhase(phase);
		move.setTemperature(temperature);
		moveCount++;
		recomputeMoveFrequencies();
	}

	/**
	 * Invokes superclass method and informs all MCMoves about the new phase.
	 */
	public boolean addPhase(Phase p) {
		if (!super.addPhase(p))
			return false;
		for (MCMoveLinker link = firstMoveLink; link != null; link = link.nextLink) {
			link.move.setPhase(phase);
{'fraction_non_alphanumeric': 0.09570154095701541, 'fraction_numerical': 0.0012165450121654502, 'mean_word_length': 3.6802656546489563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6115393', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1511, 'n_words': 529}