-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generate.c
70 lines (53 loc) · 1.35 KB
/
Generate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Interpretation.h"
#include "Sat.h"
#include "Formula.h"
#include "Generate.h"
#include<stdlib.h>
#include<stdio.h>
/**
* Generate and print a random clause with nbLiterals literals
* @param f the formula
* @param clauseNumber : the clause to generate
* @param : the number of literals that contain the clause
*/
void generateClause(Formula f,int clauseNumber, int nbLiterals) {
for(int i = 0;i<nbLiterals;i++) {
int sign = rand()%2 ? 1 : -1;
Literal l = sign*(rand()%f.nbVariables+1);
addLast(&(f.clauses[clauseNumber]),l);
}
}
/**
* Generate and print nbClauses
* @param f the formula
* @param
*/
void generateAllClauses(Formula f) {
for(int i = 0;i<f.nbClauses;i++)
generateClause(f,i,rand()%5+1);
}
/**
* Generate a full random formula
* @param number of variables
* @param number of clauses
* @return the formula
*/
void generateFullRandomFormula(Formula *f,int nbVars,int nbClauses) {
createFormula(f,nbClauses,nbVars);
generateAllClauses(*f);
}
/**
* Generate a 3-SAT random formula
* Each clause have to contain exactly 3 literals
* @param number of variables
* @param number of clauses
* Return the formula
*/
void generate3RandomFormula(Formula *f,int nbVars,int nbClauses)
{
int i ;
for ( i = 0 ; i < f->nbClauses ; i++){
int ranNbLiterals=3;
generateClause(*f,i,f->nbVariables);
}
}