[Formulas]=MakeVarDepFormulas(n,m,c,relatedvars,ratio) MakeVarDepFormulas: Creates a set of formulas (one corresponds to each objective) where some clauses have a higher probability to appear in the formula in accordance to the variables appear in them INPUT n: Number of variables m: Number of formulas (objectives) c: Number of clauses in each formula relatedvars: Vector of variables that will be more frequent in each formula ratio: Determines how often a clause appear in a formula. ratio=1 implies that all variables have the same likelihood. The weight of a clause is the sum of variables in relatedvars multiplied by the ratio. The probability of each clauses is computed normalizing its weight by the total weight OUTPUT Formulas: An array of matrices, each matrix has a row for each clause, In the row, first the variables involved are shown, then whether they are negated (0 value) or not (1 value) EXAMPLE [Formulas] = MakeVarDepFormulas(20,10,20,[1:10],5) Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function[Formulas]=MakeVarDepFormulas(n,m,c,relatedvars,ratio) 0002 % [Formulas]=MakeVarDepFormulas(n,m,c,relatedvars,ratio) 0003 % MakeVarDepFormulas: Creates a set of formulas (one corresponds to each objective) where some clauses have a higher 0004 % probability to appear in the formula in accordance to 0005 % the variables appear in them 0006 % INPUT 0007 % n: Number of variables 0008 % m: Number of formulas (objectives) 0009 % c: Number of clauses in each formula 0010 % relatedvars: Vector of variables that will be more frequent in each formula 0011 % ratio: Determines how often a clause appear in a formula. ratio=1 implies 0012 % that all variables have the same likelihood. The weight of a 0013 % clause is the sum of variables in relatedvars multiplied by the 0014 % ratio. The probability of each clauses is computed normalizing its weight by 0015 % the total weight 0016 % OUTPUT 0017 % Formulas: An array of matrices, each matrix has a row for each clause, 0018 % In the row, first the variables involved are shown, then 0019 % whether they are negated (0 value) or not (1 value) 0020 % EXAMPLE 0021 % [Formulas] = MakeVarDepFormulas(20,10,20,[1:10],5) 0022 % 0023 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0024 0025 triples = nchoosek([1:n],3); 0026 ntriples = size(triples,1); 0027 0028 for i=1:ntriples, 0029 common = intersect(relatedvars,triples(i,:)); 0030 ncommon = size(common,2); 0031 if(ncommon>1) 0032 val(i) = ratio*ncommon; 0033 else 0034 val(i) = 1; 0035 end 0036 end 0037 0038 0039 matrix = zeros(n,n); 0040 val = cumsum(val/sum(val)); 0041 0042 0043 0044 for i=1:m 0045 Index = sus(c,val); 0046 0047 for j=1:c 0048 Formulas{i,j} = [triples(Index(j),:),fix(2*rand(1,3))]; 0049 matrix(triples(Index(j),1),triples(Index(j),2)) = matrix(triples(Index(j),1),triples(Index(j),2)) + 1; 0050 matrix(triples(Index(j),1),triples(Index(j),3)) = matrix(triples(Index(j),1),triples(Index(j),3)) + 1; 0051 matrix(triples(Index(j),2),triples(Index(j),3)) = matrix(triples(Index(j),2),triples(Index(j),3)) + 1; 0052 matrix(triples(Index(j),2),triples(Index(j),1)) = matrix(triples(Index(j),2),triples(Index(j),1)) + 1; 0053 matrix(triples(Index(j),3),triples(Index(j),1)) = matrix(triples(Index(j),3),triples(Index(j),1)) + 1; 0054 matrix(triples(Index(j),3),triples(Index(j),2)) = matrix(triples(Index(j),3),triples(Index(j),2)) + 1; 0055 end 0056 end 0057 0058 %matrix 0059 %sum(matrix(1:10,1:10)) 0060 %sum(matrix(11:20,11:20))