1 /* =========FOR INTERNAL USE ONLY. NO DISTRIBUTION PLEASE ========== */
3 /*********************************************************************
4 Copyright 2000-2004, Princeton University. All rights reserved.
5 By using this software the USER indicates that he or she has read,
6 understood and will comply with the following:
8 --- Princeton University hereby grants USER nonexclusive permission
9 to use, copy and/or modify this software for internal, noncommercial,
10 research purposes only. Any distribution, including commercial sale
11 or license, of this software, copies of the software, its associated
12 documentation and/or modifications of either is strictly prohibited
13 without the prior consent of Princeton University. Title to copyright
14 to this software and its associated documentation shall at all times
15 remain with Princeton University. Appropriate copyright notice shall
16 be placed on all software copies, and a complete copy of this notice
17 shall be included in all copies of the associated documentation.
18 No right is granted to use in advertising, publicity or otherwise
19 any trademark, service mark, or the name of Princeton University.
22 --- This software and any associated documentation is provided "as is"
24 PRINCETON UNIVERSITY MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS
25 OR IMPLIED, INCLUDING THOSE OF MERCHANTABILITY OR FITNESS FOR A
26 PARTICULAR PURPOSE, OR THAT USE OF THE SOFTWARE, MODIFICATIONS, OR
27 ASSOCIATED DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS,
28 TRADEMARKS OR OTHER INTELLECTUAL PROPERTY RIGHTS OF A THIRD PARTY.
30 Princeton University shall not be liable under any circumstances for
31 any direct, indirect, special, incidental, or consequential damages
32 with respect to any claim by USER or any third party on account of
33 or arising from the use, or inability to use, this software or its
34 associated documentation, even if Princeton University has been advised
35 of the possibility of those damages.
36 *********************************************************************/
46 #include "solver_interface.h"
48 #include <sys/resource.h>
56 static inline double cpuTime(void) {
58 getrusage(RUSAGE_SELF, &ru);
59 return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
74 ptr=read(0, buffer, sizeof(int)*IS_BUFFERSIZE);
75 if (ptr == -1 || ptr == 0)
78 ssize_t bytestoread=(4-(ptr & 3)) & 3;
79 while(bytestoread != 0) {
80 ssize_t p=read(0, &((char *)buffer)[ptr], bytestoread);
81 if (p == -1 || p == 0)
90 return buffer[offset++];
93 ssize_t bytestowrite=sizeof(int)*outoffset;
94 ssize_t byteswritten=0;
96 ssize_t n=write(IS_OUT_FD, &((char *)outbuffer)[byteswritten], bytestowrite);
98 fprintf(stderr, "Write failure\n");
103 } while(bytestowrite != 0);
107 void putInt(int value) {
108 if (outoffset>=IS_BUFFERSIZE) {
111 outbuffer[outoffset++]=value;
115 void readClauses(SAT_Manager solver) {
117 bool haveClause = false;
122 while (var > numvars) {
124 SAT_AddVariable(solver);
127 clause.push_back( (lit>0) ? shvar : shvar+1);
131 SAT_AddClause(solver, & clause.begin()[0], clause.size());
143 void processCommands(SAT_Manager solver) {
145 int command=getInt();
156 int ret = SAT_Solve(solver);
158 if (ret == SATISFIABLE) {
161 for(int i=1;i<=numvars;i++) {
162 putInt(SAT_GetVarAsgnment(solver, i)==1);
164 } else if (ret == UNSATISFIABLE) {
173 fprintf(stderr, "Unreconized command\n");
178 void processSAT(SAT_Manager solver) {
179 buffer=(int *) malloc(sizeof(int)*IS_BUFFERSIZE);
182 outbuffer=(int *) malloc(sizeof(int)*IS_BUFFERSIZE);
186 double initial_time = cpuTime();
188 double parse_time = cpuTime();
189 processCommands(solver);
190 double finish_time = cpuTime();
191 printf("Parse time: %12.2f s Solve time:%12.2f s\n", parse_time-initial_time, finish_time-parse_time);
196 int main(int argc, char ** argv) {
197 SAT_Manager mng = SAT_InitManager();