Skip to content

Commit 287ccbe

Browse files
author
frankc
committed
新文件: .test.cnf.swp
删除: bin/Debug/zmaxsat 重命名: utils/ParseUtils.h -> core/Input.h 修改: core/Solver.cc 修改: core/Solver.h 修改: core/SolverTypes.h 新文件: core/debug.cc 新文件: core/debug.h 修改: core/main.cc 删除: main.cpp 新文件: maxsatz2013.c 修改: mtl/Vec.h 新文件: obj/Debug/core/Solver.o 新文件: obj/Debug/core/debug.o 修改: obj/Debug/core/main.o 新文件: obj/Debug/utils/System.o 新文件: test.cnf 删除: utils/Options.cc 删除: utils/Options.h 修改: utils/System.cc 修改: utils/System.h 新文件: zmaxsat-NSConflict-MrPigeon.layout 修改: zmaxsat.cbp 修改: zmaxsat.depend 修改: zmaxsat.layout 新文件: zmaxsat_mini.c 新文件: "\350\257\264\346\230\216.txt"
1 parent 30259b3 commit 287ccbe

27 files changed

+6134
-831
lines changed

.test.cnf.swp

12 KB
Binary file not shown.

bin/Debug/zmaxsat

-20.2 KB
Binary file not shown.

utils/ParseUtils.h core/Input.h

+71-46
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
/************************************************************************************[ParseUtils.h]
2-
Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3-
Copyright (c) 2007-2010, Niklas Sorensson
41

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6-
associated documentation files (the "Software"), to deal in the Software without restriction,
7-
including without limitation the rights to use, copy, modify, merge, publish, distribute,
8-
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9-
furnished to do so, subject to the following conditions:
10-
11-
The above copyright notice and this permission notice shall be included in all copies or
12-
substantial portions of the Software.
13-
14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15-
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18-
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19-
**************************************************************************************************/
20-
21-
#ifndef zmaxsat_ParseUtils_h
22-
#define zmaxsat_ParseUtils_h
23-
24-
#include <stdlib.h>
252
#include <stdio.h>
26-
273
#include <zlib.h>
4+
//#include "SolverTypes.h"
5+
#include "Solver.h"
286

297
namespace zmaxsat {
30-
31-
//-------------------------------------------------------------------------------------------------
32-
// A simple buffered character stream class:
33-
8+
//==============================================================================================================
9+
//data structure for input function --parseutils.h
3410
static const int buffer_size = 1048576;
35-
36-
3711
class StreamBuffer {
3812
gzFile in;
3913
unsigned char buf[buffer_size];
@@ -44,7 +18,7 @@ class StreamBuffer {
4418
if (pos >= size) {
4519
pos = 0;
4620
size = gzread(in, buf, sizeof(buf)); } }
47-
21+
//circulate reading
4822
public:
4923
explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); }
5024

@@ -53,32 +27,24 @@ class StreamBuffer {
5327
int position () const { return pos; }
5428
};
5529

56-
5730
//-------------------------------------------------------------------------------------------------
5831
// End-of-file detection functions for StreamBuffer and char*:
59-
60-
6132
static inline bool isEof(StreamBuffer& in) { return *in == EOF; }
6233
static inline bool isEof(const char* in) { return *in == '\0'; }
63-
6434
//-------------------------------------------------------------------------------------------------
6535
// Generic parse functions parametrized over the input-stream type.
66-
67-
6836
template<class B>
6937
static void skipWhitespace(B& in) {
7038
while ((*in >= 9 && *in <= 13) || *in == 32)
7139
++in; }
7240

73-
7441
template<class B>
7542
static void skipLine(B& in) {
7643
for (;;){
7744
if (isEof(in)) return;
7845
if (*in == '\n') { ++in; return; }
7946
++in; } }
80-
81-
47+
//函数功能是把字符串转换成数字
8248
template<class B>
8349
static int parseInt(B& in) {
8450
int val = 0;
@@ -91,8 +57,6 @@ static int parseInt(B& in) {
9157
val = val*10 + (*in - '0'),
9258
++in;
9359
return neg ? -val : val; }
94-
95-
9660
// String matching: in case of a match the input iterator will be advanced the corresponding
9761
// number of characters.
9862
template<class B>
@@ -101,10 +65,8 @@ static bool match(B& in, const char* str) {
10165
for (i = 0; str[i] != '\0'; i++)
10266
if (in[i] != str[i])
10367
return false;
104-
10568
in += i;
106-
107-
return true;
69+
return true;
10870
}
10971

11072
// String matching: consumes characters eagerly, but does not require random access iterator.
@@ -115,8 +77,71 @@ static bool eagerMatch(B& in, const char* str) {
11577
return false;
11678
return true; }
11779

80+
//=================================================================================================
81+
// input fuctions for instance:
82+
83+
template<class B, class Solver>
84+
static void readClause(B& in, Solver& S, vec<Lit>& lits) {
85+
int parsed_lit, var;
86+
lits.clear();
87+
for (;;){
88+
parsed_lit = parseInt(in);
89+
if (parsed_lit == 0) break;
90+
var = abs(parsed_lit)-1;
91+
while (var>= S.nVars()) S.newVar();
92+
lits.push( (parsed_lit > 0) ? mkLit(var) : ~ mkLit(var) );
93+
}
94+
}
95+
96+
template<class B, class Solver>
97+
static void parse_DIMACS_main(B& in, Solver& S) {
98+
vec<Lit> lits;
99+
int cnt= 0;
100+
for (;;){
101+
skipWhitespace(in); //略过空格
102+
if (*in == EOF) break; //读文件结束
103+
else if (*in == 'p'){
104+
if (eagerMatch(in, "p cnf")){
105+
S.setnVars(parseInt(in)); //获取变元个数
106+
S.setnClauses(parseInt(in)); //获取子句个数
107+
S.setisWeight(0);
108+
}
109+
else if(eagerMatch(in, "p wcnf")){
110+
S.setnVars(parseInt(in)); //获取变元个数
111+
S.setnClauses(parseInt(in)); //获取子句个数
112+
S.setisWeight(1);
113+
if(*in!='\n'){
114+
skipWhitespace(in);
115+
int hardweight=0;
116+
while (*in >= '0' && *in <= '9'){
117+
hardweight= hardweight*10 + (*in - '0'),
118+
++in;
119+
}
120+
S.setHardWeight(hardweight);
121+
}
122+
if(S.getHardWeight()>0)
123+
S.setPartial(1);
124+
}
125+
}
126+
else if(*in == 'c' || *in!= 'p')
127+
skipLine(in);// 略去文件开始部分的说明性信息
128+
else{ //开始读入每个子句
129+
cnt++;
130+
readClause(in, S, lits);
131+
S.addClause(lits);
132+
}
133+
}//end for
134+
if (cnt!=S.getnClauses())
135+
fprintf(stderr, "WARNING! DIMACS header mismatch: wrong number of clauses.\n");
136+
}
137+
138+
// Inserts problem into solver.
139+
//
140+
template<class Solver>
141+
static void buildInstance(gzFile input_stream, Solver& S) {
142+
StreamBuffer in(input_stream); //为文件分配一个读入的字符流缓存
143+
parse_DIMACS_main(in, S); }//读入算例的子句等信息
118144

119145
//=================================================================================================
120146
}
121147

122-
#endif

0 commit comments

Comments
 (0)