Commit 983eed9b authored by Daniel Le Berre's avatar Daniel Le Berre

More sonarqube fixes.

parent 40bc3e48
Pipeline #3357 failed with stages
in 1 minute and 19 seconds
......@@ -2397,7 +2397,7 @@ public class Solver<D extends DataStructureFactory>
this.keepHot = keepHot;
}
private final Comparator<Integer> dimacsLevel = new Comparator<Integer>() {
private final transient Comparator<Integer> dimacsLevel = new Comparator<Integer>() {
public int compare(Integer i1, Integer i2) {
return voc.getLevel(Math.abs(i2)) - voc.getLevel(Math.abs(i1));
}
......
......@@ -29,6 +29,8 @@
*******************************************************************************/
package org.sat4j.specs;
import java.io.Serializable;
/**
* Utility interface to catch objects with logging capability (able to log).
*
......@@ -38,9 +40,14 @@ package org.sat4j.specs;
* @author sroussel
* @since 2.3.3
*/
public interface ILogAble {
public interface ILogAble extends Serializable {
ILogAble CONSOLE = new ILogAble() {
/**
*
*/
private static final long serialVersionUID = 1L;
public void log(String message) {
System.out.println(message);
}
......
......@@ -29,6 +29,7 @@
*******************************************************************************/
package org.sat4j.tools;
import java.io.Serializable;
import java.util.Collection;
import org.sat4j.core.VecInt;
......@@ -37,14 +38,14 @@ import org.sat4j.specs.IVecInt;
import org.sat4j.specs.IteratorInt;
import org.sat4j.specs.TimeoutException;
public abstract class AbstractClauseSelectorSolver<T extends ISolver> extends
SolverDecorator<T> {
public abstract class AbstractClauseSelectorSolver<T extends ISolver>
extends SolverDecorator<T> {
private static final long serialVersionUID = 1L;
private int lastCreatedVar;
private boolean pooledVarId = false;
private interface SelectorState {
private interface SelectorState extends Serializable {
boolean isSatisfiable(boolean global) throws TimeoutException;
......@@ -59,6 +60,11 @@ public abstract class AbstractClauseSelectorSolver<T extends ISolver> extends
private final SelectorState external = new SelectorState() {
/**
*
*/
private static final long serialVersionUID = 1L;
private IVecInt getNegatedSelectors() {
IVecInt assumps = new VecInt();
for (int var : getAddedVars()) {
......@@ -92,6 +98,11 @@ public abstract class AbstractClauseSelectorSolver<T extends ISolver> extends
private final SelectorState internal = new SelectorState() {
/**
*
*/
private static final long serialVersionUID = 1L;
public boolean isSatisfiable(boolean global) throws TimeoutException {
return decorated().isSatisfiable(global);
}
......
......@@ -14,7 +14,7 @@ public class AbstractMinimalModel extends SolverDecorator<ISolver> {
*
*/
private static final long serialVersionUID = 1L;
protected final SortedSet<Integer> pLiterals;
protected final transient SortedSet<Integer> pLiterals;
protected final SolutionFoundListener modelListener;
public static IVecInt positiveLiterals(ISolver solver) {
......
......@@ -33,6 +33,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.Writer;
import java.util.Map;
import java.util.logging.Level;
......@@ -59,8 +60,8 @@ import org.sat4j.specs.VarMapper;
* @author daniel
* @since 2.2
*/
public class DotSearchTracing<T> extends SearchListenerAdapter<ISolverService>
implements VarMapper {
public class DotSearchTracing<T extends Serializable>
extends SearchListenerAdapter<ISolverService> implements VarMapper {
/**
*
......
......@@ -6,8 +6,13 @@ import java.io.PrintStream;
public class FileBasedVisualizationTool implements IVisualizationTool {
/**
*
*/
private static final long serialVersionUID = 1L;
private String filename;
private PrintStream out;
private transient PrintStream out;
public FileBasedVisualizationTool(String filename) {
this.filename = filename;
......@@ -16,8 +21,8 @@ public class FileBasedVisualizationTool implements IVisualizationTool {
public void updateWriter() {
try {
this.out = new PrintStream(new FileOutputStream(this.filename
+ ".dat"));
this.out = new PrintStream(
new FileOutputStream(this.filename + ".dat"));
} catch (FileNotFoundException e) {
this.out = System.out;
}
......
......@@ -44,7 +44,7 @@ import org.sat4j.specs.TimeoutException;
public class LexicoDecorator<T extends ISolver> extends SolverDecorator<T>
implements IOptimizationProblem {
protected final List<IVecInt> criteria = new ArrayList<IVecInt>();
protected final transient List<IVecInt> criteria = new ArrayList<IVecInt>();
protected int currentCriterion = 0;
......
......@@ -82,7 +82,7 @@ public class ManyCore<S extends ISolver>
private final String[] availableSolvers; // = { };
protected final List<S> solvers;
protected transient final List<S> solvers;
protected final int numberOfSolvers;
protected int winnerId;
private boolean resultFound;
......
......@@ -58,7 +58,7 @@ public class RupSearchListener<S extends ISolverService>
*/
private static final long serialVersionUID = 1L;
private PrintStream out;
private transient PrintStream out;
private final File file;
public RupSearchListener(String filename) {
......
......@@ -48,7 +48,8 @@ public class SpeedTracing extends SearchListenerAdapter<ISolverService> {
private double maxY;
public SpeedTracing(IVisualizationTool visuTool,
IVisualizationTool cleanVisuTool, IVisualizationTool restartVisuTool) {
IVisualizationTool cleanVisuTool,
IVisualizationTool restartVisuTool) {
this.visuTool = visuTool;
this.cleanVisuTool = cleanVisuTool;
this.restartVisuTool = restartVisuTool;
......@@ -70,7 +71,7 @@ public class SpeedTracing extends SearchListenerAdapter<ISolverService> {
if (this.end - this.begin >= 2000) {
long tmp = this.end - this.begin;
this.index += tmp;
y = this.counter / tmp * 1000;
y = this.counter / tmp * 1000.0;
if (y > this.maxY) {
this.maxY = y;
}
......@@ -94,8 +95,8 @@ public class SpeedTracing extends SearchListenerAdapter<ISolverService> {
public void cleaning() {
this.end = System.currentTimeMillis();
long indexClean = this.index + this.end - this.begin;
this.visuTool.addPoint(indexClean / 1000.0, this.counter
/ (this.end - this.begin) * 1000);
this.visuTool.addPoint(indexClean / 1000.0,
this.counter / (this.end - this.begin) * 1000.0);
this.cleanVisuTool.addPoint(indexClean / 1000.0, this.maxY);
this.restartVisuTool.addInvisiblePoint(indexClean, 0);
}
......@@ -104,7 +105,7 @@ public class SpeedTracing extends SearchListenerAdapter<ISolverService> {
public void restarting() {
this.end = System.currentTimeMillis();
long indexRestart = this.index + this.end - this.begin;
double y = this.counter / (this.end - this.begin) * 1000;
double y = this.counter / (this.end - this.begin) * 1000.0;
this.visuTool.addPoint(indexRestart / 1000.0, y);
if (y > this.maxY) {
this.maxY = y;
......
......@@ -29,6 +29,7 @@
*******************************************************************************/
package org.sat4j.tools;
import java.io.Serializable;
import java.util.Map;
import org.sat4j.specs.IConstr;
......@@ -43,7 +44,8 @@ import org.sat4j.specs.SearchListener;
* @author daniel
* @since 2.2
*/
public class TextOutputTracing<T> implements SearchListener<ISolverService> {
public class TextOutputTracing<T extends Serializable>
implements SearchListener<ISolverService> {
private static final long serialVersionUID = 1L;
......
......@@ -43,13 +43,13 @@ import org.sat4j.specs.IVecInt;
/**
* Implementation of product encoding for at most one and at most k constraints.
*
* The encoding for "at most one" constraints was introduced by J. Chen in
* "A New SAT Encoding for the At-Most-One Constraint" in Proceedings of the
* Tenth International Workshop of Constraint Modeling and Reformulation, 2010
* For the generalization to "at most k" constraint, we use the encoding
* introduced in A. M. Frisch and P . A. Giannaros,
* "SAT Encodings of the At-Most-k Constraint", in International Workshop on
* Modelling and Reformulating Constraint Satisfaction Problems, 2010
* The encoding for "at most one" constraints was introduced by J. Chen in "A
* New SAT Encoding for the At-Most-One Constraint" in Proceedings of the Tenth
* International Workshop of Constraint Modeling and Reformulation, 2010 For the
* generalization to "at most k" constraint, we use the encoding introduced in
* A. M. Frisch and P . A. Giannaros, "SAT Encodings of the At-Most-k
* Constraint", in International Workshop on Modelling and Reformulating
* Constraint Satisfaction Problems, 2010
*
* @author sroussel
* @since 2.3.1
......@@ -146,8 +146,8 @@ public class Product extends EncodingStrategyAdapter {
for (int d = 0; d < k + 1; d++) {
for (int i = 0; i < n; i++) {
clause.push(-literals.get(i));
clause.push(ady[d].get(recompositionBase10DepuisBaseP(
aWithoutD[i][d], p)));
clause.push(ady[d].get(
recompositionBase10DepuisBaseP(aWithoutD[i][d], p)));
group.add(solver.addClause(clause));
clause.clear();
}
......
......@@ -35,8 +35,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.URL;
import org.junit.Before;
import org.junit.Test;
import org.sat4j.maxsat.reader.WDimacsReader;
......
......@@ -29,6 +29,7 @@
*******************************************************************************/
package org.sat4j.pb;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Map;
......@@ -46,8 +47,8 @@ import org.sat4j.tools.DimacsStringSolver;
*
* @author leberre
*/
public class UserFriendlyPBStringSolver<T> extends DimacsStringSolver
implements IPBSolver {
public class UserFriendlyPBStringSolver<T extends Serializable>
extends DimacsStringSolver implements IPBSolver {
/**
*
......
......@@ -29,6 +29,7 @@
*******************************************************************************/
package org.sat4j.pb.constraints;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.math.BigInteger;
import java.util.logging.Level;
......@@ -62,7 +63,7 @@ import org.sat4j.specs.IVecInt;
public abstract class AbstractPBDataStructureFactory
extends AbstractDataStructureFactory implements PBDataStructureFactory {
interface INormalizer {
interface INormalizer extends Serializable {
PBContainer nice(IVecInt ps, IVec<BigInteger> bigCoefs,
boolean moreThan, BigInteger bigDeg, ILits voc)
throws ContradictionException;
......@@ -70,6 +71,11 @@ public abstract class AbstractPBDataStructureFactory
public static final INormalizer FOR_COMPETITION = new INormalizer() {
/**
*
*/
private static final long serialVersionUID = 1L;
public PBContainer nice(IVecInt literals, IVec<BigInteger> coefs,
boolean moreThan, BigInteger degree, ILits voc)
throws ContradictionException {
......@@ -113,6 +119,11 @@ public abstract class AbstractPBDataStructureFactory
public static final INormalizer NO_COMPETITION = new INormalizer() {
/**
*
*/
private static final long serialVersionUID = 1L;
public PBContainer nice(IVecInt literals, IVec<BigInteger> coefs,
boolean moreThan, BigInteger degree, ILits voc)
throws ContradictionException {
......
......@@ -656,7 +656,7 @@ public abstract class WatchPbLong
}
}
private final Comparator<Integer> levelBased = new Comparator<Integer>() {
private final transient Comparator<Integer> levelBased = new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return voc.getLevel(o1) - voc.getLevel(o2);
......
package org.sat4j.pb.core;
import java.io.Serializable;
import org.sat4j.core.ReadOnlyVecInt;
import org.sat4j.specs.IVecInt;
......@@ -9,7 +11,12 @@ import org.sat4j.specs.IVecInt;
* @author lonca
*
*/
public class IntegerVariable {
public class IntegerVariable implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private final IVecInt vars;
......
......@@ -30,6 +30,11 @@ import org.sat4j.specs.UnitClauseProvider;
public class SumLeximinDecompositionOWAOptimizer
implements IMultiObjOptimizationProblem, IIntegerPBSolver {
/**
*
*/
private static final long serialVersionUID = 1L;
private final List<ObjectiveFunction> objs = new ArrayList<ObjectiveFunction>();
private final BigInteger[] weights;
......
......@@ -30,7 +30,12 @@ import org.sat4j.specs.SearchListenerAdapter;
import org.sat4j.specs.TimeoutException;
public class CardConstrFinder
implements Iterator<AtLeastCard>, Iterable<AtLeastCard> {
implements Iterator<AtLeastCard>, Iterable<AtLeastCard>, Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private final IPBSolver coSolver;
......
......@@ -40,32 +40,32 @@ import org.sat4j.specs.SearchListenerAdapter;
public class ConflictTracing extends SearchListenerAdapter<ISolverService> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
private final String filename;
private PrintStream out;
private long index = 1;
private final String filename;
private transient PrintStream out;
private long index = 1;
public ConflictTracing(String filename) {
this.filename = filename;
updateWriter();
}
public ConflictTracing(String filename) {
this.filename = filename;
updateWriter();
}
private void updateWriter() {
try {
this.out = new PrintStream(new FileOutputStream(this.filename
+ ".dat"));
} catch (FileNotFoundException e) {
this.out = System.out;
}
}
private void updateWriter() {
try {
this.out = new PrintStream(
new FileOutputStream(this.filename + ".dat"));
} catch (FileNotFoundException e) {
this.out = System.out;
}
}
@Override
public void learn(IConstr c) {
PBConstr myConstr = (PBConstr) c;
if (myConstr.size() > 0) {
this.out.printf("%d %d %d%n", this.index++, myConstr.getCoef(0),
myConstr.size());
}
}
@Override
public void learn(IConstr c) {
PBConstr myConstr = (PBConstr) c;
if (myConstr.size() > 0) {
this.out.printf("%d %d %d%n", this.index++, myConstr.getCoef(0),
myConstr.size());
}
}
}
......@@ -30,6 +30,7 @@
package org.sat4j.pb.tools;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
......@@ -63,7 +64,7 @@ import org.sat4j.tools.GateTranslator;
* @param <C>
* The class of the object to map to each constraint.
*/
public class DependencyHelper<T, C> {
public class DependencyHelper<T, C> implements Serializable {
public static final INegator NO_NEGATION = new INegator() {
......@@ -105,8 +106,8 @@ public class DependencyHelper<T, C> {
}
/**
*
*/
*
*/
private static final long serialVersionUID = 1L;
private final Map<T, Integer> mapToDimacs = new HashMap<T, Integer>();
......@@ -219,8 +220,8 @@ public class DependencyHelper<T, C> {
this.mapToDomain.put(intValue, myThing);
this.mapToDimacs.put(myThing, intValue);
} else {
throw new IllegalArgumentException("" + myThing
+ " is unknown in the solver!");
throw new IllegalArgumentException(
"" + myThing + " is unknown in the solver!");
}
}
if (negated) {
......
......@@ -51,7 +51,7 @@ public class LexicoDecoratorPB extends LexicoDecorator<IPBSolver>
*/
private static final long serialVersionUID = 1L;
protected List<ObjectiveFunction> objs = new ArrayList<ObjectiveFunction>();
protected transient List<ObjectiveFunction> objs = new ArrayList<ObjectiveFunction>();
private BigInteger bigCurrentValue;
public LexicoDecoratorPB(IPBSolver solver) {
......
......@@ -45,7 +45,7 @@ public class PreprocCardConstrLearningSolver<S extends IPBSolver>
private boolean verbose = true;
private Map<Integer, BigInteger> objWeightsMap = null;
private final Map<Integer, BigInteger> objWeightsMap = new HashMap<Integer, BigInteger>();
private BigInteger objMinBound = null;
......@@ -77,7 +77,7 @@ public class PreprocCardConstrLearningSolver<S extends IPBSolver>
public void init() {
if (getObjectiveFunction() != null) {
this.objWeightsMap = new HashMap<Integer, BigInteger>();
this.objWeightsMap.clear();
IteratorInt litsIt = getObjectiveFunction().getVars().iterator();
Iterator<BigInteger> weightsIt = getObjectiveFunction().getCoeffs()
.iterator();
......
......@@ -197,6 +197,7 @@ public class GoodOPBReader extends Reader implements Serializable {
assert coeffs.size() == lits.size();
}
}
stk.close();
}
@Override
......
......@@ -159,7 +159,7 @@ public class DetailedCommandPanel extends JPanel implements SolverController,
private StartSolverEnum startConfig;
private StringWriter stringWriter;
private transient StringWriter stringWriter;
private JPanel aboutSolverPanel;
private JTextArea textArea;
......@@ -1647,7 +1647,7 @@ public class DetailedCommandPanel extends JPanel implements SolverController,
private int conflictCounter;
private PrintStream outSolutionFound;
private transient PrintStream outSolutionFound;
private void updateWriter() {
try {
......
......@@ -35,7 +35,6 @@ import org.sat4j.pb.core.PBSolverCP;
import org.sat4j.pb.reader.OPBReader2012;
import org.sat4j.pb.tools.InprocCardConstrLearningSolver;
import org.sat4j.pb.tools.PreprocCardConstrLearningSolver;
import org.sat4j.reader.ParseFormatException;
import org.sat4j.specs.ContradictionException;
import org.sat4j.specs.TimeoutException;
import org.sat4j.tools.DotSearchTracing;
......
......@@ -152,7 +152,7 @@ public class Lanceur extends AbstractLauncher implements ILogAble {
Class<?> clazz = Class
.forName("org.sat4j." + framework + ".SolverFactory"); //$NON-NLS-1$ //$NON-NLS-2$
Class<?>[] params = {};
Method m = clazz.getMethod("instance", params); //$NON-NLS-1$
clazz.getMethod("instance", params); //$NON-NLS-1$
} catch (Exception e) { // DLB Findbugs warning ok
log("Wrong framework: " + framework
+ ". Using minisat instead.");
......
......@@ -67,7 +67,7 @@ public class LaunchRemoteControl {
break;
}
RemoteControlFrame frame = new RemoteControlFrame(filename, ramdisk);
new RemoteControlFrame(filename, ramdisk);
}
......
......@@ -191,10 +191,6 @@ public class Launcher extends AbstractLauncher implements ILogAble {
setSilent(true);
}
if (cmd.hasOption("k")) {
Integer myk = Integer.valueOf(cmd.getOptionValue("k"));
}
if (cmd.hasOption("r")) {
this.modeTracing = true;
if (!cmd.hasOption("remote")) {
......
......@@ -206,9 +206,8 @@ public class RestartCommandComponent extends CommandComponent {
String choix = (String) this.listeRestarts.getSelectedItem();
boolean isNotSameRestart = !choix.equals(this.currentRestart);
boolean shouldInit = isNotSameRestart;
RestartStrategy restart = new NoRestarts();
RestartStrategy restart;
SearchParams params = this.controller.getSearchParams();
SolverStats stats = this.controller.getSolverStats();
if (choix.equals("LubyRestarts")) {
......@@ -230,7 +229,7 @@ public class RestartCommandComponent extends CommandComponent {
restart = this.controller.getRestartStrategy();
((LubyRestarts) restart).setFactor(factor);
}
shouldInit = isNotSameRestart || factorChanged;
boolean shouldInit = isNotSameRestart || factorChanged;
if (shouldInit) {
this.controller.init(params, stats);
......
......@@ -29,6 +29,8 @@
*******************************************************************************/
package org.sat4j.sat;
import java.io.Serializable;
import org.sat4j.minisat.core.IPhaseSelectionStrategy;
import org.sat4j.minisat.core.LearnedConstraintsEvaluationType;
import org.sat4j.minisat.core.RestartStrategy;
......@@ -36,7 +38,7 @@ import org.sat4j.minisat.core.SearchParams;
import org.sat4j.minisat.core.SimplificationType;
import org.sat4j.minisat.core.SolverStats;
public interface SolverController {
public interface SolverController extends Serializable {
int getNVar();
......
......@@ -82,8 +82,8 @@ public final class Solvers {
private Solvers() {
}
protected static ICDCL configureFromString(String solverconfig,
ICDCL theSolver, ILogAble logger) {
protected static ICDCL<DataStructureFactory> configureFromString(String solverconfig,
ICDCL<DataStructureFactory> theSolver, ILogAble logger) {
assert theSolver != null;
// AFAIK, there is no easy way to solve parameterized problems
// when building the solver at runtime.
......@@ -97,12 +97,12 @@ public final class Solvers {
pf.setProperty(couple[0], couple[1]);
}
Solver aSolver = (Solver) theSolver;
Solver<DataStructureFactory> aSolver = (Solver<DataStructureFactory>) theSolver;
DataStructureFactory dsf = setupObject("DSF", pf, logger);
if (dsf != null) {
theSolver.setDataStructureFactory(dsf);
}
LearningStrategy learning = setupObject(LEARNING, pf, logger);
LearningStrategy<DataStructureFactory> learning = setupObject(LEARNING, pf, logger);
if (learning != null) {
theSolver.setLearningStrategy(learning);
learning.setSolver(aSolver);
......@@ -271,7 +271,7 @@ public final class Solvers {
}
}
public static ICDCL configureSolver(String[] args, ILogAble logger) {
public static ICDCL<DataStructureFactory> configureSolver(String[] args, ILogAble logger) {
Options options = createCLIOptions();
if (args.length == 0) {
HelpFormatter helpf = new HelpFormatter();
......@@ -324,19 +324,19 @@ public final class Solvers {
factory = org.sat4j.minisat.SolverFactory.instance();
}
ICDCL<?> asolver;
ICDCL<DataStructureFactory> asolver;
if (cmd.hasOption("s")) {
String solvername = cmd.getOptionValue("s");
if (solvername == null) {
logger.log("No solver for option s. Launching default solver.");
logger.log("Available solvers: "
+ Arrays.asList(factory.solverNames()));
asolver = (Solver<?>) factory.defaultSolver();
asolver = (Solver<DataStructureFactory>) factory.defaultSolver();
} else {
asolver = (Solver<?>) factory.createSolverByName(solvername);
asolver = (Solver<DataStructureFactory>) factory.createSolverByName(solvername);
}
} else {
asolver = (Solver<?>) factory.defaultSolver();
asolver = (Solver<DataStructureFactory>) factory.defaultSolver();
}
if (cmd.hasOption("S")) {
......@@ -392,7 +392,7 @@ public final class Solvers {
if (dotfilename == null) {
dotfilename