/* cap18_3sat.c: A program for studying the random 3-sat problem. Copyright (C) 2006 Federico Ricci-Tersenghi (Federico.Ricci@roma1.infn.it) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program has been extracted from "Programmazione Scientifica", Pearson Education ed. (2006), by Barone, Marinari, Organtini and Ricci-Tersenghi. ISBN 8871922425. */ #include #include #include #define FNORM (2.3283064365e-10) #define RANDOM ( (ira[ip++]=ira[ip1++]+ira[ip2++]) ^ira[ip3++] ) #define FRANDOM (FNORM * RANDOM) #define pm1 ((FRANDOM > 0.5) ? 1 : -1) #define N 20 #define M_MIN 60 #define M_STEP 1 #define M_MAX 100 /* Variabili che si fissano al momento della creazione della formula globale */ unsigned glob_literal[3*M_MAX], max_rep; int glob_sign[3*M_MAX]; /* Variabili che si fissano al momento della creazione della subformula */ unsigned M, literal[3*M_MAX], *clause_with, num_clauses_with[N]; int sign[3*M_MAX]; /* Variabili dinamiche */ int assign[N], bb_assign[N]; unsigned bb[N], bb_size, num_sol, num_calls, num_calls_1; /* Variabili riguardanti il generatore random */ unsigned myrand, ira[256]; unsigned char ip,ip1,ip2,ip3; unsigned rand4init(void) { unsigned long long y; y = (myrand*16807LL); myrand = (y&0x7fffffff) + (y>>31); if (myrand&0x80000000) myrand = (myrand&0x7fffffff) + 1; return myrand; } void Init_Random(void) { unsigned i; ip=128; ip1=ip-24; ip2=ip-55; ip3=ip-61; for (i=ip3; i max_rep) max_rep = num_clauses_with[i]; clause_with = (unsigned*)calloc(N*max_rep, sizeof(unsigned)); } void Create_Subformula(void) { unsigned i; for (i=0; i \n", argv[0]); exit(1); } n_samples = (unsigned)atoi(argv[1]); myrand = (unsigned)atoi(argv[2]); printf("# N = %d M = %d -> %d n_samples = %d random_seed = %u\n", N, M_MIN, M_MAX, n_samples, myrand); printf("# N M num_sol bb_size num_calls num_calls_1\n"); fflush(stdout); Init_Random(); for (is=0; is