[Formulas]=MakeConfObjectivesFormulas(n,m,c,cfixed) MakeConfObjectivesFormulas: Creates a set of formulas (one correspond to each objective). The first cfixed formulas are uniformly randomly selected. The rest of formulas are constructed by randomly picked a previous generated formula and replacing some of the variables by other variables that are not in the formula. The idea is to generate conditionally independent objectives given the variables INPUT n: Number of variables m: Number of formulas (objectives) c: Number of clauses in each formula cfixed: Number of fixed formulas (the first clauses generated) OUTPUT 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). Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0001 function[Formulas]=MakeConfObjectivesFormulas(n,m,c,cfixed) 0002 % [Formulas]=MakeConfObjectivesFormulas(n,m,c,cfixed) 0003 % MakeConfObjectivesFormulas: Creates a set of formulas (one correspond to each objective). 0004 % The first cfixed formulas are uniformly randomly selected. 0005 % The rest of formulas are constructed by 0006 % randomly picked a previous generated formula 0007 % and replacing some of the variables by other 0008 % variables that are not in the formula. 0009 % The idea is to generate conditionally independent objectives given the variables 0010 % INPUT 0011 % n: Number of variables 0012 % m: Number of formulas (objectives) 0013 % c: Number of clauses in each formula 0014 % cfixed: Number of fixed formulas (the first clauses generated) 0015 % OUTPUT 0016 % Formulas{i,j}: Contains the clause j in the formula i. A clause is six 0017 % component vector. The first three components are the numbers of the 0018 % variables in the clause. The rest three component indicate whether the 0019 % literal is negated (0) or not (1). 0020 % 0021 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es) 0022 0023 clear Formulas 0024 triples = nchoosek([1:n],3); 0025 ntriples = size(triples,1); 0026 0027 val = ones(ntriples,1); 0028 0029 matrix = zeros(n,n); 0030 val = cumsum(val/sum(val)); 0031 0032 0033 0034 for i=1:cfixed % The initial formulas are randomly selected from the [1:fixedvars]; 0035 Index = sus(c,val); 0036 for j=1:c 0037 Formulas{i,j} = [triples(Index(j),:),fix(2*rand(1,3))]; 0038 end 0039 end 0040 0041 0042 for i=cfixed+1:m, % The rest of formulas are found by replacing some the literals in some of the previously generated formulas 0043 prev = fix((i-1)*rand) + 1; % Previous clause that will be used to construct the new one 0044 auxvect = zeros(1,n); 0045 for j=1:c, 0046 auxvect(Formulas{prev,j}(1:3)) = 1; 0047 end 0048 VarsIn = find(auxvect==1); 0049 totIn = size(VarsIn,2); 0050 0051 InPerm = randperm(totIn); 0052 tochange = fix((totIn)*rand)+1; % Number of variables that will change their literals 0053 VarsToChange = VarsIn(InPerm(1:tochange)); 0054 0055 for j=1:c 0056 for k=1:3 0057 found = find(VarsToChange==Formulas{prev,j}(k)); 0058 if isempty(found) 0059 Formulas{i,j}(k+3) = Formulas{prev,j}(k+3); 0060 else 0061 Formulas{i,j}(k+3) = 1-Formulas{prev,j}(k+3); 0062 end 0063 end 0064 Formulas{i,j}(1:3) = Formulas{prev,j}(1:3); 0065 end 0066 end 0067 0068 0069 0070 0071 0072 0073 %matrix 0074 %sum(matrix(1:10,1:10)) 0075 %sum(matrix(11:20,11:20))