naturalnumberfixer.java

来自「Java版的SAT求解器」· Java 代码 · 共 69 行

JAVA
69
字号
/** * <p>Title: NaturalNumberFixer</p> * <p>Description: An IProblem which constrains an INaturalNumber to a * particular value.</p> * <p>Copyright (c) 2005</p> * <p>Company: Positronic Software</p> * @author Kerry Michael Soileau * @version 1.0 */package positronic.satisfiability.naturalnumber;import positronic.satisfiability.elements.*;import positronic.satisfiability.exceptions.*;public class NaturalNumberFixer extends Problem implements IProblem{  private static final long serialVersionUID = 1L;    public NaturalNumberFixer(INaturalNumber b, boolean[] bitArray) throws Exception  {  	if(b==null)  		throw new NaturalNumberFixerException("A null INaturalNumber was passed to a constructor.");  	if(bitArray==null)  		throw new NaturalNumberFixerException("A null bitArray was passed to a constructor.");NaturalNumberBitFixer[] bnnbf      =new NaturalNumberBitFixer[INaturalNumber.LENGTH];    int a=bitArray.length;    if(a!=bnnbf.length)      throw(new NaturalNumberFixerException(        "There is a size mismatch between the INaturalNumber and the parameter (boolean[] or long) passed to a constructor."));    for(int i=0;i<a;i++)      bnnbf[i]=new NaturalNumberBitFixer(b,i,bitArray[i]);    for(int i=a;i<INaturalNumber.LENGTH;i++)      bnnbf[i]=new NaturalNumberBitFixer(b,i,false);    IProblem p=new Conjunction(bnnbf);    this.setClauses(p.getClauses());  }  public NaturalNumberFixer(INaturalNumber n) throws Exception  {  	if(n==null)  		throw new NaturalNumberFixerException("A null INaturalNumber was passed to a constructor.");    IProblem problem=new NaturalNumberBitFixer(n);    this.setClauses(problem.getClauses());  }  public NaturalNumberFixer(INaturalNumber b, long n) throws Exception  {    this(b,(      (positronic.math.INumber)new positronic.math.Number(        new positronic.math.Number(n),INaturalNumber.LENGTH)).getBitArray());  }  public NaturalNumberFixer(INaturalNumber b, String bitString) throws Exception  {  	if(b==null)  		throw new NaturalNumberFixerException("A null INaturalNumber was passed to a constructor.");  	if(bitString==null)  		throw new NaturalNumberFixerException("A null bitString was passed to a constructor.");  	NaturalNumberBitFixer[] bnnbf=new NaturalNumberBitFixer[bitString.length()];    for(int i=0;i<bnnbf.length;i++)      if(bitString.charAt(bnnbf.length-1-i)=='1')        bnnbf[i]=new NaturalNumberBitFixer(b,i,true);      else        bnnbf[i]=new NaturalNumberBitFixer(b,i,false);    IProblem p=new Conjunction(bnnbf);    this.setClauses(p.getClauses());  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?