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

# MakeRandomFormulas

## PURPOSE

[Formulas]=MakeRandomFormulas(n,m,c)

## SYNOPSIS

function[Formulas]=MakeRandomFormulas(n,m,c)

## DESCRIPTION

     [Formulas]=MakeRandomFormulas(n,m,c)
     MakeVarDepFormulas: Creates a set of formulas (one correspond to each objective). Clauses are uniformly randomly selected.
     INPUT
     n: Number of variables
     m: Number of formulas (objectives)
     c: Number of clauses in each formula
     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] = MakeRandomFormulas(20,10,20)

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

## CROSS-REFERENCE INFORMATION

This function calls:

- sus [Index]=sus(SelCant,Sumvector)

This function is called by:

## SOURCE CODE

    0001 function[Formulas]=MakeRandomFormulas(n,m,c)
    0002 % [Formulas]=MakeRandomFormulas(n,m,c)
    0003 % MakeVarDepFormulas: Creates a set of formulas (one correspond to each objective). Clauses are uniformly randomly selected.
    0004 % INPUT
    0005 % n: Number of variables
    0006 % m: Number of formulas (objectives)
    0007 % c: Number of clauses in each formula
    0008 % OUTPUT
    0009 % Formulas: An array of matrices, each matrix has a row for each clause,
    0010 %           In the row, first the variables involved are shown, then
    0011 %           whether they are negated (0 value) or not (1 value)
    0012 % EXAMPLE
    0013 %  [Formulas] = MakeRandomFormulas(20,10,20)
    0014 %
    0015 % Last version 8/26/2008. Roberto Santana (roberto.santana@ehu.es)
    0016
    0017 triples = nchoosek([1:n],3);
    0018 ntriples = size(triples,1);
    0019
    0020  val = ones(ntriples,1);
    0021
    0022  matrix = zeros(n,n);
    0023  val = cumsum(val/sum(val));
    0024
    0025
    0026
    0027  for i=1:m
    0028     Index = sus(c,val);
    0029
    0030    for j=1:c
    0031      Formulas{i,j} = [triples(Index(j),:),fix(2*rand(1,3))];
    0032      matrix(triples(Index(j),1),triples(Index(j),2)) = matrix(triples(Index(j),1),triples(Index(j),2)) + 1;
    0033      matrix(triples(Index(j),1),triples(Index(j),3)) = matrix(triples(Index(j),1),triples(Index(j),3)) + 1;
    0034      matrix(triples(Index(j),2),triples(Index(j),3)) = matrix(triples(Index(j),2),triples(Index(j),3)) + 1;
    0035      matrix(triples(Index(j),2),triples(Index(j),1)) = matrix(triples(Index(j),2),triples(Index(j),1)) + 1;
    0036      matrix(triples(Index(j),3),triples(Index(j),1)) = matrix(triples(Index(j),3),triples(Index(j),1)) + 1;
    0037      matrix(triples(Index(j),3),triples(Index(j),2)) = matrix(triples(Index(j),3),triples(Index(j),2)) + 1;
    0038    end
    0039  end
    0040
    0041  %matrix
    0042  %sum(matrix(1:10,1:10))
    0043  %sum(matrix(11:20,11:20))