[valfun] = EvaluateSAT(solution) EvaluateSAT: Evaluates a solution on a set of 3-SAT formulas contained in the global variable Formulas. The output is a multi-objective solution, one component corresponds to the evaluation of one formula. INPUTS solution: Binary vector Formulas{i,j}: Contains the clause j in the formula i. A clause is six component vector. The first three components are the numbers of the variables in the clause. The rest three component indicate whether the literal is negated (0) or not (1). OUTPUTS valfun: A vector of m components. valfun(i) is the number of clauses satisfied in formula i. Last version 2/17/2009. Roberto Santana (roberto.santana@ehu.es)
0001 function[valfun] = EvaluateSAT(solution) 0002 % [valfun] = EvaluateSAT(solution) 0003 % EvaluateSAT: Evaluates a solution on a set of 3-SAT formulas contained in the 0004 % global variable Formulas. The output is a multi-objective 0005 % solution, one component corresponds to the evaluation of one 0006 % formula. 0007 % 0008 % INPUTS 0009 % solution: Binary vector 0010 % Formulas{i,j}: Contains the clause j in the formula i. A clause is six 0011 % component vector. The first three components are the numbers of the 0012 % variables in the clause. The rest three component indicate whether the 0013 % literal is negated (0) or not (1). 0014 % OUTPUTS 0015 % valfun: A vector of m components. valfun(i) is the number of clauses 0016 % satisfied in formula i. 0017 % 0018 % Last version 2/17/2009. Roberto Santana (roberto.santana@ehu.es) 0019 0020 global Formulas; 0021 0022 n = size(solution,2); % number of variables 0023 m = size(Formulas,1); % number of formulas (objectives) 0024 c = size(Formulas,2); % number of clauses 0025 valfun = zeros(1,m); 0026 0027 for i=1:m, 0028 for j=1:c, 0029 auxclause(1:3) = solution(Formulas{i,j}(1:3)); 0030 auxclause(4:6) = Formulas{i,j}(4:6); 0031 valfun(i) = valfun(i) + ( xor(auxclause(1),auxclause(4)) + xor(auxclause(2),auxclause(5)) + xor(auxclause(3),auxclause(6)) <3); 0032 end, 0033 end, 0034