org.chocosolver.solver.search.restart.LubyCutoff Maven / Gradle / Ivy
Show all versions of choco-solver Show documentation
/*
* This file is part of choco-solver, http://choco-solver.org/
*
* Copyright (c) 2023, 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.solver.search.restart;
/**
* 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 LubyCutoff extends AbstractCutoff {
/**
* 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 LubyCutoff(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)";
}
}