com.ibm.wala.dataflow.IFDS.BoundedPartiallyBalancedSolver Maven / Gradle / Ivy
/*
* Copyright (c) 2008 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.dataflow.IFDS;
import com.ibm.wala.util.MonitorUtil.IProgressMonitor;
/**
* A {@link TabulationSolver} that gives up after a finite bound.
*
* @param type of node in the supergraph
* @param type of a procedure (like a box in an RSM)
* @param type of factoids propagated when solving this problem
*/
public class BoundedPartiallyBalancedSolver
extends PartiallyBalancedTabulationSolver {
private static final boolean VERBOSE = false;
public static
BoundedPartiallyBalancedSolver createdBoundedPartiallyBalancedSolver(
PartiallyBalancedTabulationProblem p, int bound, IProgressMonitor monitor) {
return new BoundedPartiallyBalancedSolver<>(p, bound, monitor);
}
private final int bound;
private int numSteps = 0;
protected BoundedPartiallyBalancedSolver(
PartiallyBalancedTabulationProblem p, int bound, IProgressMonitor monitor) {
super(p, monitor);
this.bound = bound;
}
@Override
protected boolean propagate(T s_p, int i, T n, int j) {
if (numSteps < bound) {
numSteps++;
return super.propagate(s_p, i, n, j);
} else {
if (VERBOSE) {
System.err.println(
"Suppressing propagation; reached bound " + s_p + ' ' + i + ' ' + n + ' ' + j);
}
return false;
}
}
public int getNumSteps() {
return numSteps;
}
public void resetBound() {
numSteps = 0;
}
}