Home > Mateda2.0 > functions > sat > MakeIndObjectivesFormulas.m

MakeIndObjectivesFormulas

PURPOSE ^

[Formulas]=MakeIndObjectivesFormulas(n,m,c,cfixed,fixedvars)

SYNOPSIS ^

function[Formulas]=MakeIndObjectivesFormulas(n,m,c,cfixed,fixedvars)

DESCRIPTION ^

 [Formulas]=MakeIndObjectivesFormulas(n,m,c,cfixed,fixedvars) 
 MakeIndObjectivesFormulas: 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)
 fixedvars: Number of variables that form the fixed formulas
 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).
 EXAMPLE
  [Formulas] = MakeRandomFormulas(20,10,20) 

 Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function[Formulas]=MakeIndObjectivesFormulas(n,m,c,cfixed,fixedvars) 
0002 % [Formulas]=MakeIndObjectivesFormulas(n,m,c,cfixed,fixedvars)
0003 % MakeIndObjectivesFormulas: 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 % fixedvars: Number of variables that form the fixed formulas
0016 % OUTPUT
0017 % Formulas{i,j}: Contains the clause j in the formula i. A clause is six
0018 % component vector. The first three components are the numbers of the
0019 % variables in the clause. The rest three component indicate whether the
0020 % literal is negated (0) or not (1).
0021 % EXAMPLE
0022 %  [Formulas] = MakeRandomFormulas(20,10,20)
0023 %
0024 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
0025 
0026 clear Formulas
0027 triples = nchoosek([1:fixedvars],3);
0028 ntriples = size(triples,1);
0029 
0030  val = ones(ntriples,1);
0031 
0032  matrix = zeros(n,n);
0033  val = cumsum(val/sum(val));
0034 
0035 
0036  
0037  for i=1:cfixed  % The initial formulas are randomly selected from the [1:fixedvars];
0038     Index = sus(c,val);  
0039    for j=1:c
0040      Formulas{i,j} = [triples(Index(j),:),fix(2*rand(1,3))];
0041    end 
0042  end
0043  
0044  
0045   for i=cfixed+1:m,           % The rest of formulas are found by replacing some of the variables in the previously generated formulas
0046    tochange = fix((fixedvars+1)*rand);   % Number of variables that will be changed (from 0 to fixedvar)
0047    prev = fix((i-1)*rand) + 1;  % Previous clause that will be used to construct the new one
0048    if tochange==0    
0049     for j=1:c,
0050      Formulas{i,j} = Formulas{prev,j}(:);
0051     end
0052    else
0053     auxvect = zeros(1,n);
0054     for j=1:c,
0055      auxvect(Formulas{prev,j}(1:3)) = 1;
0056     end 
0057     VarsIn = find(auxvect==1);
0058     InPerm = randperm(fixedvars);
0059     VarsOut = setdiff([1:n],VarsIn);
0060     OutPerm = randperm(n-fixedvars);
0061     VarsToTakeOut = VarsIn(InPerm(1:tochange));
0062     VarsToTakeIn =  VarsOut(OutPerm(1:tochange));
0063     for j=1:c
0064       for k=1:3
0065         found = find(VarsToTakeOut==Formulas{prev,j}(k));
0066         if isempty(found)
0067           Formulas{i,j}(k) = Formulas{prev,j}(k);
0068         else 
0069           Formulas{i,j}(k) = VarsToTakeIn(found);
0070         end         
0071       end  
0072       Formulas{i,j}(4:6) = Formulas{prev,j}(4:6);
0073     end      
0074    end
0075   end
0076   
0077    
0078  
0079  
0080    
0081  
0082  %matrix
0083  %sum(matrix(1:10,1:10))
0084  %sum(matrix(11:20,11:20))

Generated on Fri 04-Dec-2009 13:38:29 by m2html © 2003