package infosapient.resolution;
/*
* Copyright (c) 2001, Workplace Performance Tools, All Rights Reserved.
*
* LICENSE TO USE THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THE COMMON PUBLIC LICENSE 0.5
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
* The license may be viewed at:
* http://www.opensource.org/licenses/cpl.html
*/
import java.rmi.server.ObjID;
/**
*
* @author: Michael McConnell
* @version $Revision: 1.1.1.1 $
*/
public class FzyImplicationMINMAX extends FzyImplicationMethod {
static final long serialVersionUID = -7304175013008886533L;
public FzyImplicationMINMAX() {myID = new ObjID();}
public synchronized void applyImplicationMethod(
infosapient.system.FzySet fs,
infosapient.system.FzySolutionSet sSet)
throws infosapient.system.FzySystemException {
fSet = fs;
solSet = sSet;
int nbrOfVals;
FS_VECMAX = fSet.getVECMAX();
SOLSET_VECMAX = solSet.getVECMAX();
fsDomain = new double[FS_VECMAX];
fsMembership = new double[FS_VECMAX];
solSetDomain = new double[SOLSET_VECMAX];
solSetMembership = new double[SOLSET_VECMAX];
fsDomain = fSet.getDomainArray();
fsMembership = fSet.getMemberArray();
solSetDomain = solSet.getDomainArray();
solSetMembership = solSet.getMemberArray();
this.found = false;
if ((solSet.isEmpty()) || (solSet.integrateMbr() == 0.0d))
initialSet();
else {
if (!found)
rightOverlap();
if (!found)
leftOverlap();
if (!found)
solutionSetOverlaps();
if (!found)
fsSetOverlaps();
if (!found)
disjointLeft();
if (!found)
disjointRight();
}
if (found) {
replaceArrays();
} else {
throw new infosapient.system.FzySystemException(
this.getName()
+ " Cannot add set: "
+ fSet.getName()
+ " to: "
+ solSet.getQualifiedName());
}
}
/**
* This condition means that the fzySet to be added completely overlaps the new set.
*/
protected void fsSetOverlaps() {
if ((solSet.getLowDomain() >= fSet.getLowDomain())
&& (solSet.getHighDomain() <= fSet.getHighDomain())) {
this.found = true;
solSet.incrementSetCount();
int fInx = 0;
int sInx = 0;
localDomain = new double[SOLSET_VECMAX];
localMembership = new double[SOLSET_VECMAX];
double delta = Math.abs(localDomain[1] - localDomain[0]);
while (true) {
if ((fInx >= SOLSET_VECMAX) || (sInx >= FS_VECMAX))
break;
if (Math.abs(localDomain[fInx] - fsDomain[sInx]) <= delta) {
localMembership[fInx] = Math.max(fsMembership[sInx], localMembership[fInx]);
fInx++;
} else if (localDomain[fInx] < fsDomain[sInx])
fInx++;
else if (localDomain[fInx] > fsDomain[sInx])
sInx++;
}
}
}
public String getName() { return "minMax"; }
/**
* This condition means that the new set is shifted to the LEFT
* of the existing set, but partially overlap to some extent.
*/
protected void leftOverlap() {
if ((solSet.getHighDomain() >= fSet.getHighDomain())
&& (solSet.getLowDomain() >= fSet.getLowDomain())
&& (solSet.getLowDomain() <= fSet.getHighDomain())) {
this.found = true;
solSet.incrementSetCount();
for (currInx = 0; currInx < FS_VECMAX; currInx++)
if (solSet.getLowDomain() <= fsDomain[currInx])
break;
nbrOfVals = currInx + SOLSET_VECMAX;
localDomain = new double[nbrOfVals];
localMembership = new double[nbrOfVals];
for (jx = 0; jx < SOLSET_VECMAX; jx++) {
localMembership[jx + currInx] = solSetMembership[jx];
localDomain[jx + currInx] = solSetDomain[jx];
}
for (jx = 0; jx < FS_VECMAX; jx++) {
localMembership[jx] = Math.max(localMembership[jx], fsMembership[jx]);
localDomain[jx] = fsDomain[jx];
}
}
}
/**
* This condition means that the added set will be added to the
* RIGHT but still partially overlap the existing set.
*/
protected void rightOverlap() {
if ((solSet.getLowDomain() <= fSet.getLowDomain())
&& (solSet.getHighDomain() <= fSet.getHighDomain())
&& (solSet.getHighDomain() >= fSet.getLowDomain())) {
this.found = true;
solSet.incrementSetCount();
for (currInx = 0; currInx < SOLSET_VECMAX; currInx++)
if (solSetDomain[currInx] >= fSet.getLowDomain())
break;
nbrOfVals = currInx + FS_VECMAX;
localDomain = new double[nbrOfVals];
localMembership = new double[nbrOfVals];
for (jx = 0; jx < solSetMembership.length; jx++) {
localMembership[jx] = solSetMembership[jx];
localDomain[jx] = solSetDomain[jx];
}
for (ix = 0; ix < FS_VECMAX; ix++) {
localDomain[ix + currInx] = fsDomain[ix];
localMembership[ix + currInx] =
Math.max(localMembership[currInx + ix], fsMembership[ix]);
}
}
}
/**
* This condition means that the solution set completely overlaps the new
* set.
*/
protected void solutionSetOverlaps() {
if ((solSet.getLowDomain() <= fSet.getLowDomain())
&& (solSet.getHighDomain() >= fSet.getHighDomain())) {
this.found = true;
solSet.incrementSetCount();
int fInx = 0;
int sInx = 0;
localDomain = new double[SOLSET_VECMAX];
localMembership = new double[SOLSET_VECMAX];
double delta = Math.abs(localDomain[1] - localDomain[0]);
while (true) {
if ((fInx >= SOLSET_VECMAX) || (sInx >= FS_VECMAX))
break;
if (Math.abs(localDomain[fInx] - fsDomain[sInx]) <= delta) {
localMembership[fInx] = Math.max(fsMembership[sInx], localMembership[fInx]);
fInx++;
} else if (localDomain[fInx] < fsDomain[sInx])
fInx++;
else if (localDomain[fInx] > fsDomain[sInx])
sInx++;
}
}
}
}