Skip to content

Instantly share code, notes, and snippets.

@Sumith1896
Last active September 27, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sumith1896/ee699d2541d5c0f8ca64b945aa293863 to your computer and use it in GitHub Desktop.
Save Sumith1896/ee699d2541d5c0f8ca64b945aa293863 to your computer and use it in GitHub Desktop.
weightgen calculate weight
float Main::CalculateSolutionWeightNonFactored(Solver &solver){
double weightTotal = 0;
for (int i = 0;i<conf.weightVariables;i++){
Var var = weightVariables.at(i);
//printf("%d %d\n",var, solver.model[var]);
if (solver.model[var] == l_True){
weightTotal = weightTotal*2+1;
}
else{
weightTotal *= 2;
}
}
weightTotal = conf.minAssignWeight*(1 + (conf.ratio-1)*weightTotal*1.0/
(pow(2,conf.weightVariables)-1));
return weightTotal/maxProb;
}
float Main::CalculateSolutionWeight(Solver &solver, vec<lbool> model){
if (conf.non_factored){
return CalculateSolutionWeightNonFactored(solver);
}
float weightTotal = 1;
for (Var var = 0; var != solver.nOrigVars();var++){
weightTotal *= solver.getWeight(var+1,model[var]);
}
weightTotal = weightTotal/maxProb;
return weightTotal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment