コード例 #1
0
ファイル: rnovelty.c プロジェクト: MattBBaker/ubcsat
void PickRNoveltyPlus()
{
 
  UINT32 iClause;
  UINT32 iClauseLen;
  LITTYPE litPick;

  /* with probability (iWp) uniformly choose an unsatisfied clause,
     and then uniformly choose a literal from that clause */

  if (RandomProb(iWp)) {
    if (iNumFalse) {
      iClause = aFalseList[RandomInt(iNumFalse)];
      iClauseLen = aClauseLen[iClause];
      litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]);
      iFlipCandidate = GetVarFromLit(litPick);
    } else {
      iFlipCandidate = 0;
    }
    return;
  }

  /* otherwise, perform a regular RNovelty step */

  PickRNoveltyCore();

}
コード例 #2
0
ファイル: weighted.c プロジェクト: pmatos/maxsatzilla
void InitMakeBreakW() {
  unsigned int j;
  unsigned int k;
  unsigned int iVar;
  LITTYPE *pLit;
  
  for (j=1;j<=iNumVar;j++) {
    aMakeCountW[j] = 0.0f;
    aBreakCountW[j] = 0.0f;
  }

  fFalseTotalW = 0.0f;
  
  for (j=0;j<iNumClause;j++) {
    if (aNumTrueLit[j]==0) {
      for (k=0;k<aClauseLen[j];k++) {
        aMakeCountW[GetVar(j,k)] += aClauseWeight[j];
      }
      fFalseTotalW += aClauseWeight[j];
    } else if (aNumTrueLit[j]==1) {
      pLit = pClauseLits[j];
      for (k=0;k<aClauseLen[j];k++) {
        if IsLitTrue(*pLit) {
          iVar = GetVarFromLit(*pLit);
          aBreakCountW[iVar] += aClauseWeight[j];
          aCritSat[j] = iVar; /* this may cause trouble for gwsatW */
          break;
        }
        pLit++;
      }
    }
  }
コード例 #3
0
ファイル: random.c プロジェクト: MattBBaker/ubcsat
void PickCRWalk() {
  
  UINT32 iClause;
  UINT32 iClauseLen;

  LITTYPE litPick;

  if (iNumFalse) {
    iClause = aFalseList[RandomInt(iNumFalse)];
    iClauseLen = aClauseLen[iClause];
    litPick = (pClauseLits[iClause][RandomInt(iClauseLen)]);
    iFlipCandidate = GetVarFromLit(litPick);
  }
}
コード例 #4
0
ファイル: hwsat.c プロジェクト: pmatos/maxsatzilla
void PickHWSAT() {
    unsigned int iClause;
    LITTYPE litPick;
    if (fxnRandomRatio(iWpNum,iWpDen)) {
        if (iNumFalse) {
            iClause = aFalseList[fxnRandomInt(iNumFalse)];
            litPick = pClauseLits[iClause][fxnRandomInt(aClauseLen[iClause])];
            iFlipCandidate = GetVarFromLit(litPick);
        } else {
            iFlipCandidate = 0;
        }
    } else
        PickHSAT();
}
コード例 #5
0
ファイル: rnovelty.c プロジェクト: pmatos/maxsatzilla
void PickRNOVELTY()
{
 
  unsigned int iClause;
  unsigned int iClauseLen;
  LITTYPE litPick;

  if ((iStep % 100) == 0) {
    if (iNumFalse) {
      iClause = aFalseList[fxnRandomInt(iNumFalse)];
      iClauseLen = aClauseLen[iClause];
      litPick = (pClauseLits[iClause][fxnRandomInt(iClauseLen)]);
      iFlipCandidate = GetVarFromLit(litPick);
    } else {
      iFlipCandidate = 0;
    }
    return;
  }
  
  PickRNOVELTYCore();
}
コード例 #6
0
ファイル: walksat.c プロジェクト: MattBBaker/ubcsat
void PickWalkSatSKC() {
 
  UINT32 i;
  UINT32 j;
  SINT32 iScore;
  UINT32 iClause;
  UINT32 iClauseLen;
  UINT32 iVar;
  LITTYPE *pLit;
  UINT32 *pClause;
  LITTYPE litPick;
  UINT32 iNumOcc;

  iNumCandidates = 0;
  iBestScore = iNumClauses;

  /* select an unsatisfied clause uniformly at random */

  if (iNumFalse) {
    iClause = aFalseList[RandomInt(iNumFalse)];
    iClauseLen = aClauseLen[iClause];
  } else {
    iFlipCandidate = 0;
    return;
  }

  pLit = pClauseLits[iClause];

  for (j=0;j<iClauseLen;j++) {

    /* for WalkSAT variants, it's faster to calculate the
       score for each literal than to cache the values 
    
       note that in this case, score is just the breakcount[] */

    iScore = 0;
    
    iVar = GetVarFromLit(*pLit);
    
    iNumOcc = aNumLitOcc[GetNegatedLit(*pLit)];
    pClause = pLitClause[GetNegatedLit(*pLit)];
    
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause]==1) {
        iScore++;
      }
      pClause++;
    }

    /* build candidate list of best vars */

    if (iScore <= iBestScore) {
      if (iScore < iBestScore) {
        iNumCandidates=0;
        iBestScore = iScore;
      }
      aCandidateList[iNumCandidates++] = iVar;
    }

    pLit++;
  }

  /* if the best step is a worsening step, then with
     probability (iWp) randomly choose the literal to flip */

  if (iBestScore > 0) {
    if (RandomProb(iWp)) {
      litPick = pClauseLits[iClause][RandomInt(iClauseLen)];
      iFlipCandidate = GetVarFromLit(litPick);
      return;
    }
  }

  /* select flip candidate uniformly from candidate list */
  
  if (iNumCandidates > 1) {
    iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
  } else {
    iFlipCandidate = aCandidateList[0];
  }
}
コード例 #7
0
ファイル: walksat.c プロジェクト: MattBBaker/ubcsat
void PickWalkSatSKCW() {

  /* weighted varaint -- see regular algorithm for comments */

  UINT32 i;
  UINT32 j;
  FLOAT fScore;
  UINT32 iClause;
  UINT32 iClauseLen;
  UINT32 iVar;
  LITTYPE *pLit;
  UINT32 *pClause;
  LITTYPE litPick;
  UINT32 iNumOcc;

  iNumCandidates = 0;
  fBestScore = fTotalWeight;

  /* select the clause according to a weighted scheme */

  if (iNumFalse) {
    iClause = PickClauseWCS();
    iClauseLen = aClauseLen[iClause];
  } else {
    iFlipCandidate = 0;
    return;
  }

  pLit = pClauseLits[iClause];
  for (j=0;j<iClauseLen;j++) {
    fScore = FLOATZERO;
    iVar = GetVarFromLit(*pLit);
    iNumOcc = aNumLitOcc[GetNegatedLit(*pLit)];
    pClause = pLitClause[GetNegatedLit(*pLit)];
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause]==1) {
        fScore += aClauseWeight[*pClause];
      }
      pClause++;
    }
    if (fScore <= fBestScore) {
      if (fScore < fBestScore) {
        iNumCandidates=0;
        fBestScore = fScore;
      }
      aCandidateList[iNumCandidates++] = iVar;
    }
    pLit++;
  }
  if (fBestScore > FLOATZERO) {
    if (RandomProb(iWp)) {
      litPick = pClauseLits[iClause][RandomInt(iClauseLen)];
      iFlipCandidate = GetVarFromLit(litPick);
      return;
    }
  }
  if (iNumCandidates > 1) {
    iFlipCandidate = aCandidateList[RandomInt(iNumCandidates)];
  } else {
    iFlipCandidate = aCandidateList[0];
  }
}
コード例 #8
0
ファイル: walksat-tabu.c プロジェクト: pmatos/maxsatzilla
void PickWALKSATTABU()
{
 
  unsigned int i;
  unsigned int j;
  int iScore;
  unsigned int iClauseLen;
  LITTYPE *pLit;
  LITTYPE *pClause;
  unsigned int iNumOcc;
  unsigned int iVar;

  iNumCandidates = 0;
  iBestScore = iNumClause+1;

  if (iNumFalse) {
    iWalkSATTabuClause = aFalseList[fxnRandomInt(iNumFalse)];
    iClauseLen = aClauseLen[iWalkSATTabuClause];
  } else {
    iFlipCandidate = 0;
    return;
  }


  pLit = pClauseLits[iWalkSATTabuClause];

  for (j=0;j<iClauseLen;j++) {
    iScore = 0;

    iVar = GetVarFromLit(*pLit);
    
    iNumOcc = aNumLitOcc[GetNegatedLit(*pLit)];
    pClause = pLitClause[GetNegatedLit(*pLit)];
    
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause++]==1) {
        iScore++;
      }
    }

    if ((iScore==0)||(aVarLastChange[iVar] + (signed int) iTabuTenure < (signed int) iStep)) { 
      if (iScore == iBestScore) {
        aCandidateList[iNumCandidates++] = iVar;
      } else if (iScore < iBestScore) {
        *aCandidateList = iVar;
        iNumCandidates=1;
        iBestScore = iScore;
      }
    }
    pLit++;
  }

  if (iNumCandidates == 0) {
    iFlipCandidate = 0;
    return;
  }

    if (iNumCandidates > 1)
      iFlipCandidate = aCandidateList[fxnRandomInt(iNumCandidates)];
    else
      iFlipCandidate = aCandidateList[0];

}
コード例 #9
0
ファイル: rnovelty.c プロジェクト: MattBBaker/ubcsat
void PickRNoveltyCore() {

  /* see the Novelty() code for general comments */
 
  UINT32 i;
  UINT32 j;
  SINT32 iScore;
  UINT32 iClause;
  UINT32 iClauseLen;
  LITTYPE *pLit;
  UINT32 *pClause;

  UINT32 iNumOcc;
  UINT32 iVar;

  UINT32 iYoungestVar;

  SINT32 iSecondBestScore;
  SINT32 iScoreMargin;
  
  UINT32 iBestVar=0;
  UINT32 iSecondBestVar=0;

  iBestScore = iNumClauses;
  iSecondBestScore = iNumClauses;

  if (iNumFalse) {
    iClause = aFalseList[RandomInt(iNumFalse)];
    iClauseLen = aClauseLen[iClause];
  } else {
    iFlipCandidate = 0;
    return;
  }

  pLit = pClauseLits[iClause];
  iYoungestVar = GetVarFromLit(*pLit);
  for (j=0;j<iClauseLen;j++) {
    iScore = 0;
    iVar = GetVarFromLit(*pLit);
    iNumOcc = aNumLitOcc[*pLit];
    pClause = pLitClause[*pLit];
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause]==0) {
        iScore--;
      }
      pClause++;
    }
    iNumOcc = aNumLitOcc[GetNegatedLit(*pLit)];
    pClause = pLitClause[GetNegatedLit(*pLit)];
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause]==1) {
        iScore++;
      }
      pClause++;
    }
    if (aVarLastChange[iVar] > aVarLastChange[iYoungestVar]) {
      iYoungestVar = iVar;
    }
    if ((iScore < iBestScore) || ((iScore == iBestScore) && (aVarLastChange[iVar] < aVarLastChange[iBestVar]))) {
      iSecondBestVar = iBestVar;
      iBestVar = iVar;
      iSecondBestScore = iBestScore;
      iBestScore = iScore;
    } else if ((iScore < iSecondBestScore) || ((iScore == iSecondBestScore) && (aVarLastChange[iVar] < aVarLastChange[iSecondBestVar]))) {
      iSecondBestVar = iVar;
      iSecondBestScore = iScore;
    }
    pLit++;
  }
  
  iFlipCandidate = iBestVar;

  /* if the best is the youngest, select it */

  if (iFlipCandidate != iYoungestVar) {
    return;
  }

  /* otherwise, calculate difference between 'best' and 'second best' */

  iScoreMargin = iSecondBestScore - iBestScore;

  /* if novnoise < 0.5 always choose best if the margin is > 1,
     and choose the second best with noise (novnoise * 2) if margin is 1 */

  if ((iNovNoise < 0x7FFFFFFF)) {
    if (iScoreMargin > 1) {
      return;
    }
    if (iScoreMargin == 1) {
      if (RandomProb(iNovNoise << 1)) {
        iFlipCandidate = iSecondBestVar;
      }
      return;
    }
  }

  /* if novnoise >= 0.5 always choose second best if the margin is = 1,
     and choose the second best with noise (1 - novnoise) * 2 if margin is > 1 */

  if (iScoreMargin == 1) {
    iFlipCandidate = iSecondBestVar;
    return;
  } 

  if (RandomProb(((iNovNoise - 0x7FFFFFFF)<<1))) {
    iFlipCandidate = iSecondBestVar;
  }
}
コード例 #10
0
ファイル: weighted.c プロジェクト: pmatos/maxsatzilla
void FlipMakeBreakW() {

  unsigned int j;
  unsigned int k;
  unsigned int *pClause;
  unsigned int iVar;
  LITTYPE litWasTrue;
  LITTYPE litWasFalse;
  LITTYPE *pLit;

  if (iFlipCandidate == 0)
    return;

  litWasTrue = GetTrueLit(iFlipCandidate);
  litWasFalse = GetFalseLit(iFlipCandidate);

  aVarValue[iFlipCandidate] = 1 - aVarValue[iFlipCandidate];

  pClause = pLitClause[litWasTrue];
  for (j=0;j<aNumLitOcc[litWasTrue];j++) {
    aNumTrueLit[*pClause]--;
    if (aNumTrueLit[*pClause]==0) { 
      
      aFalseList[iNumFalse] = *pClause;
      aFalseListPos[*pClause] = iNumFalse++;

      fFalseTotalW += aClauseWeight[*pClause];

      aBreakCountW[iFlipCandidate] -= aClauseWeight[*pClause];
      
      pLit = pClauseLits[*pClause];
      for (k=0;k<aClauseLen[*pClause];k++) {
        aMakeCountW[GetVarFromLit(*pLit)] += aClauseWeight[*pClause];
        pLit++;
      }
    }
    if (aNumTrueLit[*pClause]==1) {
      pLit = pClauseLits[*pClause];
      for (k=0;k<aClauseLen[*pClause];k++) {
        if (IsLitTrue(*pLit)) {
          iVar = GetVarFromLit(*pLit);
          aBreakCountW[iVar] += aClauseWeight[*pClause];
          aCritSat[*pClause] = iVar;
          break;
        }
        pLit++;
      }
    }
    pClause++;
  }

  pClause = pLitClause[litWasFalse];
  for (j=0;j<aNumLitOcc[litWasFalse];j++) {
    aNumTrueLit[*pClause]++;
    if (aNumTrueLit[*pClause]==1) {

      aFalseList[aFalseListPos[*pClause]] = aFalseList[--iNumFalse];
      aFalseListPos[aFalseList[iNumFalse]] = aFalseListPos[*pClause];

      fFalseTotalW -= aClauseWeight[*pClause];

      pLit = pClauseLits[*pClause];
      for (k=0;k<aClauseLen[*pClause];k++) {
        iVar = GetVarFromLit(*pLit);
        aMakeCountW[iVar] -= aClauseWeight[*pClause];
        pLit++;
      }
      aBreakCountW[iFlipCandidate] += aClauseWeight[*pClause];
      aCritSat[*pClause] = iFlipCandidate;
    }
    if (aNumTrueLit[*pClause]==2) {
      aBreakCountW[aCritSat[*pClause]] -= aClauseWeight[*pClause];
    }
    *pClause++;
  }
}
コード例 #11
0
ファイル: rnovelty.c プロジェクト: pmatos/maxsatzilla
void PickRNOVELTYCore()
{
 
  unsigned int i;
  unsigned int j;
  signed int iScore;
  unsigned int iClause;
  unsigned int iClauseLen;
  LITTYPE *pLit;
  LITTYPE *pClause;

  unsigned int iNumOcc;
  unsigned int iVar;

  unsigned int iYoungestVar;

  signed int iSecondBestScore;
  signed int iScoreMargin;
  
  unsigned int iBestVar=0;
  unsigned int iSecondBestVar=0;

  unsigned int iNovNoiseDenDiv2 = iNovNoiseDen >> 1;


  iBestScore = iNumClause+1;
  iSecondBestScore = iNumClause+1;

  if (iNumFalse) {
    iClause = aFalseList[fxnRandomInt(iNumFalse)];
    iClauseLen = aClauseLen[iClause];
  } else {
    iFlipCandidate = 0;
    return;
  }

  pLit = pClauseLits[iClause];

  iYoungestVar = GetVarFromLit(*pLit);

  for (j=0;j<iClauseLen;j++) {
    iScore = 0;

    iVar = GetVarFromLit(*pLit);

    iNumOcc = aNumLitOcc[*pLit];
    pClause = pLitClause[*pLit];
    
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause++]==0) {
        iScore--;
      }
    }

    iNumOcc = aNumLitOcc[GetNegatedLit(*pLit)];
    pClause = pLitClause[GetNegatedLit(*pLit)];
    
    for (i=0;i<iNumOcc;i++) {
      if (aNumTrueLit[*pClause++]==1) {
        iScore++;
      }
    }

    if (aVarLastChange[iVar] > aVarLastChange[iYoungestVar])
      iYoungestVar = iVar;

    if ((iScore < iBestScore) || ((iScore == iBestScore) && (aVarLastChange[iVar] < aVarLastChange[iBestVar]))) {
      iSecondBestVar = iBestVar;
      iBestVar = iVar;
      iSecondBestScore = iBestScore;
      iBestScore = iScore;
    } else if ((iScore < iSecondBestScore) || ((iScore == iSecondBestScore) && (aVarLastChange[iVar] < aVarLastChange[iSecondBestVar]))) {
      iSecondBestVar = iVar;
      iSecondBestScore = iScore;
    }

    pLit++;
  }
  
  iFlipCandidate = iBestVar;

  if (iFlipCandidate != iYoungestVar)
    return;

  iScoreMargin = iSecondBestScore - iBestScore;

  if ((iNovNoiseNum < iNovNoiseDenDiv2)) {
    if (iScoreMargin > 1)
      return;
    if (iScoreMargin == 1) {
      if (fxnRandomRatio(iNovNoiseNum << 1,iNovNoiseDen))
        iFlipCandidate = iSecondBestVar;
      return;
    }
  }
  if (iScoreMargin == 1) {
    iFlipCandidate = iSecondBestVar;
    return;
  } 

  if (fxnRandomRatio(((iNovNoiseNum - iNovNoiseDenDiv2)<<1),iNovNoiseDen))
    iFlipCandidate = iSecondBestVar;
}