All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.chocosolver.cutoffseq.LubyCutoffStrategy Maven / Gradle / Ivy

There is a newer version: 4.10.17
Show newest version
/*
 * This file is part of choco-solver, http://choco-solver.org/
 *
 * Copyright (c) 2022, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
package org.chocosolver.cutoffseq;

/**
 * A Luby cutoff strategy.
 * 

* Based on: *
* "Optimal Speedup of Las Vegas Algorithms", * M. Luby, A. Sinclair, D. Zuckerman, * IPL: Information Processing Letters, 1993, 47, 173-180. *
*

* Example, with s=1: * 1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, 1, 1, 2, ... * * @author Charles Prud'homme, Arnaud Malapert, Hadrien Cambazard * @since 13/05/11 */ public final class LubyCutoffStrategy extends AbstractCutoffStrategy { /** * Current cutoff, starts at 1 and will be multiplied by {@link #scaleFactor} * anytime {@link #getNextCutoff()} is called. */ private int un = 1; /** * Current limit, which set {@link #un} to 1 when reached. */ private int vn = 1; /** * A Luby cutoff strategy. * * @param s scale factor */ @SuppressWarnings("WeakerAccess") public LubyCutoffStrategy(long s) { super(s); } /** * From SAT 2012: computing Luby values the way presented by Donald Knuth * in his invited talk at the SAT 2012 conference. *
* Credits: sat4j. */ @Override public long getNextCutoff() { final long cutoff = scaleFactor * this.vn; if ((this.un & -this.un) == this.vn) { this.un = this.un + 1; this.vn = 1; } else { this.vn = this.vn << 1; } return cutoff; } @Override public void reset() { un = vn = 1; } @Override public String toString() { return "LUBY(s=" + scaleFactor + ",log2)"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy