init commit
This commit is contained in:
parent
31f02dda01
commit
78f6ae93e3
68
README.md
68
README.md
@ -0,0 +1,68 @@
|
||||
# 甘棠约束条件编码器
|
||||
|
||||
## 使用方法
|
||||
|
||||
Linux 二进制已经编译好了,直接 ./encoder 即可。
|
||||
|
||||
自动读取当前目录 ./data 下的三个 csv 文件作为程序输入,如果需要修改输入数据,就改那三个 csv 文件(一定要UTF-8编码的,因为文件里有中文,Office Excel 转成的 csv 是 GBK 编码的,需要额外处理一下)。
|
||||
|
||||
```bash
|
||||
约束条件可以使用任意数理逻辑表达式,包括 =>、<=、()、!、~、&、|、<=>,并且可以任意嵌套
|
||||
运算符默认优先级 (~|!) > (&) > (|) > (=>) = (<=) > (<=>)
|
||||
```
|
||||
|
||||
程序的标准输出就是 CNF 格式的,并且包含合理的注释信息,直接重定向就可以:
|
||||
|
||||
```bash
|
||||
./encoder > result.cnf
|
||||
```
|
||||
|
||||
## 如何编译
|
||||
|
||||
比较懒没有写 makefile,.h 和 .cpp 文件之间互相依赖太多了,基本改了一个就要全部重新编译,所以直接用脚本,每次重新全部编译。
|
||||
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
|
||||
没有使用系统调用,在 Windows 上编译也可以直接编译通过,也是同样的编译命令。
|
||||
|
||||
## 正确性
|
||||
|
||||
在给定的示例编码文件中,最终编码文件 result.cnf 在 appmc 和 projMC 的计算中,都为 36288,和给定的目标完全一致。
|
||||
|
||||
projMC 的程序好像是有数组越界的 BUG,需要稍微把 p cnf 中的变量数量改的比实际变量的范围和数量要大一点才不会报错,appmc 没有问题。
|
||||
|
||||
```
|
||||
> approxmc --epsilon 0.05 result.cnf
|
||||
c Total time (this thread) : 0.67
|
||||
c [appmc+arjun] Total time: 0.67
|
||||
c [appmc] Number of solutions is: 4536*2**3
|
||||
s SATISFIABLE
|
||||
s mc 36288
|
||||
|
||||
> ./binary/projMC_linux -fpv=name_nbvar.var result.cnf
|
||||
c Projected Model Counter Information
|
||||
c Number of recursive calls: 16
|
||||
c Number of decomposable AND nodes: 17
|
||||
c Number of UNSAT subproblems: 3
|
||||
c Number of positive hits: 2
|
||||
c
|
||||
c Final time: 0.015772
|
||||
c
|
||||
s 36288
|
||||
```
|
||||
|
||||
## 编码思路
|
||||
|
||||
对于基本可选特征值和特征族的编码,可以用传统方式直接编码,最麻烦的一个部分是约束条件的形式是一个没有任何特殊性质的数理逻辑表达式(&、|、~、=>、<=>、()、!),并且可以任意组合,因此需要构造一个通用的语法分析器。
|
||||
|
||||
### 语法分析
|
||||
|
||||
使用 LR(1)/LALR(1) 文法自动机对每个约束语句进行语法分析,按照数理逻辑的符号优先级定义规约顺序,并且规则设定为左结合优先,使二义性文法符合 LR(1) 文法,利用文法构造器,去生成语法分析代码框架。
|
||||
|
||||
### 语法制导
|
||||
|
||||
按照自底向上的语法制导方法,每次依次合并两个变量或者取反,用新的变量等价代替它,然后将新的变量压入栈中,这样会有状态数过多的问题。
|
||||
|
||||
实际上连续的析取和合取子句,只需要一个等价的变量去代替就可以了,因此构建一个新的类代表若干个子句的析取或合取式子,重载该类的所有操作,遇到必须合并的时候再整体等价为一个变量操作。
|
BIN
binary/projMC_linux
Normal file
BIN
binary/projMC_linux
Normal file
Binary file not shown.
2
build.sh
Normal file
2
build.sh
Normal file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
g++ src/CalculatorParser.cpp src/Main.cpp src/Allocate.cpp src/CNF.cpp -O3 -std=c++17 -o encoder
|
238
data/是否必选特征族.csv
Normal file
238
data/是否必选特征族.csv
Normal file
@ -0,0 +1,238 @@
|
||||
序号,销售车型编码,特征族编码,是否必选
|
||||
1,TEST01,A8088382906,是
|
||||
2,TEST01,A8088382908,是
|
||||
3,TEST01,A8088382909,是
|
||||
4,TEST01,A8088382910,是
|
||||
5,TEST01,A8088382912,是
|
||||
6,TEST01,A8088382915,是
|
||||
7,TEST01,A8088382919,是
|
||||
8,TEST01,A8088382920,是
|
||||
9,TEST01,A8088382923,是
|
||||
10,TEST01,A8088382928,是
|
||||
11,TEST01,A8088382930,是
|
||||
12,TEST01,A8088382933,是
|
||||
13,TEST01,A8088382934,是
|
||||
14,TEST01,A8088382936,是
|
||||
15,TEST01,A8088382939,是
|
||||
16,TEST01,A8088382940,是
|
||||
17,TEST01,A8088382942,是
|
||||
18,TEST01,A8088382945,是
|
||||
19,TEST01,A8088382947,是
|
||||
20,TEST01,A8088382948,是
|
||||
21,TEST01,A8088382949,是
|
||||
22,TEST01,A8088382953,是
|
||||
23,TEST01,A8088382954,是
|
||||
24,TEST01,A8088382955,是
|
||||
25,TEST01,A8088382956,是
|
||||
26,TEST01,A8088382959,是
|
||||
27,TEST01,A8088382960,是
|
||||
28,TEST01,A8088382961,是
|
||||
29,TEST01,A8088382971,是
|
||||
30,TEST01,A8088382972,是
|
||||
31,TEST01,A8088382974,是
|
||||
32,TEST01,A8088382977,是
|
||||
33,TEST01,A8088382982,是
|
||||
34,TEST01,A8088382984,是
|
||||
35,TEST01,A8088382986,是
|
||||
36,TEST01,A8088382987,是
|
||||
37,TEST01,A8088382988,是
|
||||
38,TEST01,A8088382989,是
|
||||
39,TEST01,A8088382991,是
|
||||
40,TEST01,A8088382992,是
|
||||
41,TEST01,A8088382993,是
|
||||
42,TEST01,A8088382994,是
|
||||
43,TEST01,A8088382996,是
|
||||
44,TEST01,A8088382997,是
|
||||
45,TEST01,A8088383002,是
|
||||
46,TEST01,A8088383005,是
|
||||
47,TEST01,A8088383009,是
|
||||
48,TEST01,A8088383010,是
|
||||
49,TEST01,A8088383011,是
|
||||
50,TEST01,A8088383012,是
|
||||
51,TEST01,A8088383014,是
|
||||
52,TEST01,A8088383018,是
|
||||
53,TEST01,A8088383019,是
|
||||
54,TEST01,A8088383020,是
|
||||
55,TEST01,A8088383021,是
|
||||
56,TEST01,A8088383022,是
|
||||
57,TEST01,A8088383024,是
|
||||
58,TEST01,A8088383029,是
|
||||
59,TEST01,A8088383030,是
|
||||
60,TEST01,A8088383034,是
|
||||
61,TEST01,A8088383036,是
|
||||
62,TEST01,A8088383037,是
|
||||
63,TEST01,A8088383039,是
|
||||
64,TEST01,A8088383040,是
|
||||
65,TEST01,A8088383042,是
|
||||
66,TEST01,A8088383043,是
|
||||
67,TEST01,A8088383046,是
|
||||
68,TEST01,A8088383047,是
|
||||
69,TEST01,A8088383048,是
|
||||
70,TEST01,A8088383049,是
|
||||
71,TEST01,A8088383050,是
|
||||
72,TEST01,A8088383051,是
|
||||
73,TEST01,A8088383054,是
|
||||
74,TEST01,A8088383057,是
|
||||
75,TEST01,A8088383059,是
|
||||
76,TEST01,A8088383064,是
|
||||
77,TEST01,A8088383067,是
|
||||
78,TEST01,A8088383068,是
|
||||
79,TEST01,A8088383070,是
|
||||
80,TEST01,A8088383071,是
|
||||
81,TEST01,A8088383072,是
|
||||
82,TEST01,A8088383073,是
|
||||
83,TEST01,A8088383075,是
|
||||
84,TEST01,A8088383083,是
|
||||
85,TEST01,A8088383084,是
|
||||
86,TEST01,A8088383085_AP-1,是
|
||||
87,TEST01,A8088383085_AP-2,是
|
||||
88,TEST01,A8088383085_AP-3,是
|
||||
89,TEST01,A8088383086,是
|
||||
90,TEST01,A8088383089,是
|
||||
91,TEST01,A8088383090,是
|
||||
92,TEST01,A8088383091,是
|
||||
93,TEST01,A8088383092,是
|
||||
94,TEST01,A8088383093,是
|
||||
95,TEST01,A8088383094,是
|
||||
96,TEST01,A8088383096,是
|
||||
97,TEST01,A8088383099,是
|
||||
98,TEST01,A8088383105,是
|
||||
99,TEST01,A8088383107,是
|
||||
100,TEST01,A8088383108,是
|
||||
101,TEST01,A8088383109,是
|
||||
102,TEST01,A8088383118,是
|
||||
103,TEST01,A8088383120,是
|
||||
104,TEST01,A8088383122,是
|
||||
105,TEST01,A8088383130,是
|
||||
106,TEST01,A8088383133,是
|
||||
107,TEST01,A8088383139,是
|
||||
108,TEST01,A8088383143,是
|
||||
109,TEST01,A8088383144,是
|
||||
110,TEST01,A8088383145,是
|
||||
111,TEST01,A8088383146,是
|
||||
112,TEST01,A8088383149,是
|
||||
113,TEST01,A8088383150,是
|
||||
114,TEST01,A8088383151,是
|
||||
115,TEST01,A8088383152,是
|
||||
116,TEST01,A8088383153,是
|
||||
117,TEST01,A8088383154,是
|
||||
118,TEST01,A8088383155,是
|
||||
119,TEST01,A8088383159,是
|
||||
120,TEST01,A8088383160,是
|
||||
121,TEST01,A8088383163,是
|
||||
122,TEST01,A8088383165,是
|
||||
123,TEST01,A8088383169,是
|
||||
124,TEST01,A8088383170,是
|
||||
125,TEST01,A8088383176,是
|
||||
126,TEST01,A8088383181,是
|
||||
127,TEST01,A8088383182,是
|
||||
128,TEST01,A8088383183,是
|
||||
129,TEST01,A8088383184,是
|
||||
130,TEST01,A8088383185,是
|
||||
131,TEST01,A8088383189,是
|
||||
132,TEST01,A8088383190,是
|
||||
133,TEST01,A8088383191,是
|
||||
134,TEST01,A8088389461,是
|
||||
135,TEST01,A8129009430,是
|
||||
136,TEST01,A8130212104,是
|
||||
137,TEST01,A8130218285,是
|
||||
138,TEST01,A8132534722,是
|
||||
139,TEST01,A8132565715,是
|
||||
140,TEST01,A8133696776,是
|
||||
141,TEST01,A8133703916,是
|
||||
142,TEST01,A8133728830,是
|
||||
143,TEST01,A8134836166,是
|
||||
144,TEST01,A8134856799,是
|
||||
145,TEST01,A8147586459,是
|
||||
146,TEST01,A8150106844,是
|
||||
147,TEST01,A8218592989,是
|
||||
148,TEST01,A8235299888,是
|
||||
149,TEST01,A8236984717,是
|
||||
150,TEST01,A8238806396,是
|
||||
151,TEST01,A8238822364,是
|
||||
152,TEST01,A8240441229,是
|
||||
153,TEST01,A8242038029,是
|
||||
154,TEST01,A8245325114,是
|
||||
155,TEST01,A8247709306,是
|
||||
156,TEST01,A8247710572,是
|
||||
157,TEST01,A8247710818,是
|
||||
158,TEST01,A8249270116,是
|
||||
159,TEST01,A8249270719,是
|
||||
160,TEST01,A8249270825,是
|
||||
161,TEST01,A8249271073,是
|
||||
162,TEST01,A8276674900,是
|
||||
163,TEST01,A8387261123,是
|
||||
164,TEST01,A8405143036,是
|
||||
165,TEST01,A8408490681,是
|
||||
166,TEST01,A8408492609,是
|
||||
167,TEST01,A8486081323,是
|
||||
168,TEST01,A8565145791,是
|
||||
169,TEST01,A8565155034,是
|
||||
170,TEST01,A8583136039,是
|
||||
171,TEST01,A8583148769,是
|
||||
172,TEST01,A8583224847,是
|
||||
173,TEST01,A8688949972,是
|
||||
174,TEST01,A8770692605,是
|
||||
175,TEST01,A8770692765,是
|
||||
176,TEST01,A8833045633,是
|
||||
177,TEST01,MB_2FT,是
|
||||
178,TEST01,MB_CK,是
|
||||
179,TEST01,MB_CMF,是
|
||||
180,TEST01,MB_DO,是
|
||||
181,TEST01,MB_EF,是
|
||||
182,TEST01,MB_FW,是
|
||||
183,TEST01,MB_TR,是
|
||||
184,TEST01,A8088382964,否
|
||||
185,TEST01,A8088382995,否
|
||||
186,TEST01,A8088383001,否
|
||||
187,TEST01,A8088383027,否
|
||||
188,TEST01,A8088383062,否
|
||||
189,TEST01,A8088383066,否
|
||||
190,TEST01,A8088383079,否
|
||||
191,TEST01,A8088383085_AP-R,否
|
||||
192,TEST01,A8088383087,否
|
||||
193,TEST01,A8088383095,否
|
||||
194,TEST01,A8088383097,否
|
||||
195,TEST01,A8088383104,否
|
||||
196,TEST01,A8088383106,否
|
||||
197,TEST01,A8088383129,否
|
||||
198,TEST01,A8088383134,否
|
||||
199,TEST01,A8088383142,否
|
||||
200,TEST01,A8088383158,否
|
||||
201,TEST01,A8088383161,否
|
||||
202,TEST01,A8088383171,否
|
||||
203,TEST01,A8132543233,否
|
||||
204,TEST01,A8132543303,否
|
||||
205,TEST01,A8132543712,否
|
||||
206,TEST01,A8133704162,否
|
||||
207,TEST01,A8133718802,否
|
||||
208,TEST01,A8134840666,否
|
||||
209,TEST01,A8134896521,否
|
||||
210,TEST01,A8134902324,否
|
||||
211,TEST01,A8218505828,否
|
||||
212,TEST01,A8218621069,否
|
||||
213,TEST01,A8219533203,否
|
||||
214,TEST01,A8219534112,否
|
||||
215,TEST01,A8219554553,否
|
||||
216,TEST01,A8223795058,否
|
||||
217,TEST01,A8236984887,否
|
||||
218,TEST01,A8238604496,否
|
||||
219,TEST01,A8238849646,否
|
||||
220,TEST01,A8238851748,否
|
||||
221,TEST01,A8238871437,否
|
||||
222,TEST01,A8303611888,否
|
||||
223,TEST01,A8405138477,否
|
||||
224,TEST01,A8469783998,否
|
||||
225,TEST01,A8620459012,否
|
||||
226,TEST01,A8633749842,否
|
||||
227,TEST01,A8695503860,否
|
||||
228,TEST01,A8718209024,否
|
||||
229,TEST01,A8741776772,否
|
||||
230,TEST01,A8827994616,否
|
||||
231,TEST01,MB_EX,否
|
||||
232,TEST01,MB_LW,否
|
||||
233,TEST01,MB_MT,否
|
||||
234,TEST01,MB_RS,否
|
||||
235,TEST01,MB_SM,否
|
||||
236,TEST01,MB_SW,否
|
||||
237,TEST01,MB_WT,否
|
|
BIN
data/是否必选特征族.xls
Normal file
BIN
data/是否必选特征族.xls
Normal file
Binary file not shown.
318
data/销售配置表.csv
Normal file
318
data/销售配置表.csv
Normal file
@ -0,0 +1,318 @@
|
||||
序号,特征族编码,特征徝编码,TEST01,,,符合条件数量36288,参与穷举特征族
|
||||
1,A8088382906,F2H,S,,,,A8134836166
|
||||
2,A8088382908,D0S,S,,,,A8387261123
|
||||
3,A8088382909,D8L,S,,,,A8238851748
|
||||
4,A8088382910,M8Y,S,,,,A8088382936
|
||||
5,A8088382912,X3H,S,,,,A8633749842
|
||||
6,A8088382915,K0W,S,,,,A8088383105
|
||||
7,A8088382919,S1L,S,,,,A8088383027
|
||||
8,A8088382920,F5Y,S,,,,A8088383104
|
||||
9,A8088382923,M5D,S,,,,A8088382933
|
||||
10,A8088382928,Z4P,S,,,,A8088383153
|
||||
11,A8088382930,I6X,S,,,,A8219534112
|
||||
12,A8088382933,J5R,S,,,,A8088383154
|
||||
13,A8088382934,W2U,S,,,,A8129009430
|
||||
14,A8088382936,D4T,S,,,,A8695503860
|
||||
15,A8088382939,A1G,S,,,,A8238604496
|
||||
16,A8088382940,S8C,S,,,,A8088383085_AP-R
|
||||
17,A8088382942,K0T,S,,,,A8132543303
|
||||
18,A8088382945,R1Q,S,,,,A8088382964
|
||||
19,A8088382945,R7S,O,,,,A8088383142
|
||||
20,A8088382947,U1S,S,,,,A8088383185
|
||||
21,A8088382948,Q0R,-,,,,A8088383064
|
||||
22,A8088382948,Q4K,S,,,,A8219554553
|
||||
23,A8088382949,D3F,S,,,,A8088383062
|
||||
24,A8088382953,Q5J,-,,,,A8134896521
|
||||
25,A8088382953,Q5U,S,,,,A8088383146
|
||||
26,A8088382954,M6M,S,,,,A8088383068
|
||||
27,A8088382955,C6K,S,,,,A8088383189
|
||||
28,A8088382956,Q1K,S,,,,A8088383067
|
||||
29,A8088382959,E1K,O,,,,A8088383143
|
||||
30,A8088382959,E1L,S,,,,A8088383066
|
||||
31,A8088382960,S5Z,S,,,,A8088382915
|
||||
32,A8088382961,S1D,S,,,,A8088382959
|
||||
33,A8088382964,D4Y,S,,,,A8827994616
|
||||
34,A8088382964,D4Z,O,,,,A8088383085_AP-1
|
||||
35,A8088382971,F4Y,S,,,,A8088383085_AP-2
|
||||
36,A8088382972,C6C,S,,,,A8088383085_AP-3
|
||||
37,A8088382974,H8X,S,,,,A8088382995
|
||||
38,A8088382977,Z5X,S,,,,A8088383005
|
||||
39,A8088382982,D6F,S,,,,A8088383049
|
||||
40,A8088382982,D6G,O,,,,A8088382994
|
||||
41,A8088382984,J1V,S,,,,A8132543712
|
||||
42,A8088382986,Y4Z,S,,,,A8620459012
|
||||
43,A8088382987,F4I,S,,,,A8132543233
|
||||
44,A8088382988,G1W,-,,,,A8088382997
|
||||
45,A8088382988,G1X,-,,,,A8088382953
|
||||
46,A8088382988,G2B,-,,,,A8088383129
|
||||
47,A8088382988,G2E,S,,,,A8088383097
|
||||
48,A8088382989,I1W,S,,,,A8088383095
|
||||
49,A8088382989,I2F,O,,,,A8132534722
|
||||
50,A8088382991,F2A,S,,,,A8088383134
|
||||
51,A8088382992,G5A,S,,,,A8150106844
|
||||
52,A8088382993,K3M,S,,,,A8088383176
|
||||
53,A8088382994,D1N,S,,,,A8088383094
|
||||
54,A8088382994,D2D,O,,,,A8088383171
|
||||
55,A8088382995,D6I,-,,,,A8088383050
|
||||
56,A8088382996,F2W,S,,,,A8088382948
|
||||
57,A8088382997,K2R,S,,,,A8088382908
|
||||
58,A8088382997,K8M,-,,,,A8088382909
|
||||
59,A8088382997,K8T,-,,,,A8303611888
|
||||
60,A8088383001,S8B,O,,,,A8133718802
|
||||
61,A8088383002,B1F,S,,,,A8088382982
|
||||
62,A8088383005,I1V,S,,,,A8134902324
|
||||
63,A8088383005,I2E,O,,,,A8088383158
|
||||
64,A8088383009,B4L,-,,,,A8218592989
|
||||
65,A8088383009,B4M,S,,,,A8088382945
|
||||
66,A8088383010,S1H,S,,,,A8088382989
|
||||
67,A8088383011,C8B,S,,,,A8223795058
|
||||
68,A8088383012,M4A,-,,,,A8088382986
|
||||
69,A8088383012,M4B,-,,,,A8088383087
|
||||
70,A8088383012,Z5E,S,,,,A8133703916
|
||||
71,A8088383014,M7I,S,,,,A8088383084
|
||||
72,A8088383018,F1R,S,,,,A8405138477
|
||||
73,A8088383019,IZY,S,,,,A8238806396
|
||||
74,A8088383020,E0P,S,,,,A8218621069
|
||||
75,A8088383021,O0A,S,,,,A8088383089
|
||||
76,A8088383022,O1X,S,,,,A8088383165
|
||||
77,A8088383024,C5P,S,,,,A8088383083
|
||||
78,A8088383027,U2I,O,,,,
|
||||
79,A8088383029,G5G,S,,,,
|
||||
80,A8088383030,F1I,S,,,,
|
||||
81,A8088383034,U1W,S,,,,
|
||||
82,A8088383036,F0X,S,,,,
|
||||
83,A8088383037,Q6Z,S,,,,
|
||||
84,A8088383039,F2P,S,,,,
|
||||
85,A8088383040,F7A,S,,,,
|
||||
86,A8088383042,O1Y,S,,,,
|
||||
87,A8088383043,A5D,O,,,,
|
||||
88,A8088383043,A6Y,S,,,,
|
||||
89,A8088383046,I4I,S,,,,
|
||||
90,A8088383047,D2Y,S,,,,
|
||||
91,A8088383048,I6N,S,,,,
|
||||
92,A8088383049,F3B,S,,,,
|
||||
93,A8088383049,F3C,O,,,,
|
||||
94,A8088383050,B1B,O,,,,
|
||||
95,A8088383050,B1U,S,,,,
|
||||
96,A8088383051,F6C,S,,,,
|
||||
97,A8088383054,C7F,S,,,,
|
||||
98,A8088383057,B2A,S,,,,
|
||||
99,A8088383059,C1N,S,,,,
|
||||
100,A8088383062,D6M,-,,,,
|
||||
101,A8088383064,J2I,S,,,,
|
||||
102,A8088383064,J2K,O,,,,
|
||||
103,A8088383066,Q0A,O,,,,
|
||||
104,A8088383067,Q0W,S,,,,
|
||||
105,A8088383068,S1P,S,,,,
|
||||
106,A8088383068,S1W,O,,,,
|
||||
107,A8088383070,A1Z,S,,,,
|
||||
108,A8088383071,I6K,S,,,,
|
||||
109,A8088383072,J3V,S,,,,
|
||||
110,A8088383073,B5I,S,,,,
|
||||
111,A8088383075,E3L,S,,,,
|
||||
112,A8088383079,B3J,-,,,,
|
||||
113,A8088383083,Q6D,S,,,,
|
||||
114,A8088383084,F3W,S,,,,
|
||||
115,A8088383084,F3Y,O,,,,
|
||||
116,A8088383085_AP-1,F38MEA 0C,O,,,,
|
||||
117,A8088383085_AP-1,F58L96 81,-,,,,
|
||||
118,A8088383085_AP-1,F58LFA 0C,-,,,,
|
||||
119,A8088383085_AP-1,F58MEA 0C,-,,,,
|
||||
120,A8088383085_AP-1,V18MEA 0C,S,,,,
|
||||
121,A8088383085_AP-2,AP-2 F38MFA 0C,O,,,,
|
||||
122,A8088383085_AP-2,AP-2 F58L96 81,-,,,,
|
||||
123,A8088383085_AP-2,AP-2 F58L98 81,-,,,,
|
||||
124,A8088383085_AP-2,AP-2 V18MFA 0C,S,,,,
|
||||
125,A8088383085_AP-3,AP-3 F38MFA 0C,O,,,,
|
||||
126,A8088383085_AP-3,AP-3 F58L96 81,-,,,,
|
||||
127,A8088383085_AP-3,AP-3 F58L98 81,-,,,,
|
||||
128,A8088383085_AP-3,AP-3 V18MFA 0C,S,,,,
|
||||
129,A8088383085_AP-R,AP-B F38MEA 0C,O,,,,
|
||||
130,A8088383085_AP-R,AP-B F38MFA 0C,-,,,,
|
||||
131,A8088383085_AP-R,AP-B F58L96 81,-,,,,
|
||||
132,A8088383085_AP-R,AP-B F58L98 81,-,,,,
|
||||
133,A8088383085_AP-R,AP-B F58LFA 0C,-,,,,
|
||||
134,A8088383085_AP-R,AP-B F58MEA 0C,-,,,,
|
||||
135,A8088383085_AP-R,AP-B V18MEA 0C,O,,,,
|
||||
136,A8088383085_AP-R,AP-B V18MFA 0C,-,,,,
|
||||
137,A8088383086,C6I,S,,,,
|
||||
138,A8088383087,D7J,O,,,,
|
||||
139,A8088383089,Q4X,S,,,,
|
||||
140,A8088383090,M5C,S,,,,
|
||||
141,A8088383091,D3C,S,,,,
|
||||
142,A8088383092,C5B,S,,,,
|
||||
143,A8088383093,F7T,S,,,,
|
||||
144,A8088383094,K4X,S,,,,
|
||||
145,A8088383094,K8K,-,,,,
|
||||
146,A8088383094,K8L,-,,,,
|
||||
147,A8088383094,K8N,-,,,,
|
||||
148,A8088383095,D7A,-,,,,
|
||||
149,A8088383096,F7X,S,,,,
|
||||
150,A8088383097,F5L,O,,,,
|
||||
151,A8088383099,K5Q,S,,,,
|
||||
152,A8088383104,L1H,O,,,,
|
||||
153,A8088383105,J1H,S,,,,
|
||||
154,A8088383106,M0E,-,,,,
|
||||
155,A8088383107,B1G,S,,,,
|
||||
156,A8088383108,M8B,S,,,,
|
||||
157,A8088383109,Z2H,S,,,,
|
||||
158,A8088383118,I6D,S,,,,
|
||||
159,A8088383120,E6I,S,,,,
|
||||
160,A8088383122,M7T,S,,,,
|
||||
161,A8088383129,R8P,O,,,,
|
||||
162,A8088383130,E1N,S,,,,
|
||||
163,A8088383133,A2U,S,,,,
|
||||
164,A8088383134,R8F,O,,,,
|
||||
165,A8088383139,F8E,S,,,,
|
||||
166,A8088383142,Y1X,O,,,,
|
||||
167,A8088383143,Y4A,S,,,,
|
||||
168,A8088383144,I5F,S,,,,
|
||||
169,A8088383145,L3A,S,,,,
|
||||
170,A8088383146,D1E,S,,,,
|
||||
171,A8088383146,D1R,O,,,,
|
||||
172,A8088383146,D2E,O,,,,
|
||||
173,A8088383149,L1B,S,,,,
|
||||
174,A8088383150,F7C,S,,,,
|
||||
175,A8088383151,Z4M,-,,,,
|
||||
176,A8088383151,Z5I,S,,,,
|
||||
177,A8088383152,K7N,S,,,,
|
||||
178,A8088383153,F5B,S,,,,
|
||||
179,A8088383154,E7F,S,,,,
|
||||
180,A8088383155,X2T,S,,,,
|
||||
181,A8088383158,E0D,O,,,,
|
||||
182,A8088383159,IZS,S,,,,
|
||||
183,A8088383160,Z5Q,S,,,,
|
||||
184,A8088383161,C8H,S,,,,
|
||||
185,A8088383163,C5D,S,,,,
|
||||
186,A8088383165,H1J,S,,,,
|
||||
187,A8088383169,C6Q,S,,,,
|
||||
188,A8088383170,Z5Y,S,,,,
|
||||
189,A8088383171,Z4R,-,,,,
|
||||
190,A8088383176,J6A,S,,,,
|
||||
191,A8088383176,J6C,-,,,,
|
||||
192,A8088383181,M5V,S,,,,
|
||||
193,A8088383182,D7R,S,,,,
|
||||
194,A8088383183,F6I,S,,,,
|
||||
195,A8088383184,C8I,S,,,,
|
||||
196,A8088383185,K5M,S,,,,
|
||||
197,A8088383189,S5A,S,,,,
|
||||
198,A8088383189,S5E,-,,,,
|
||||
199,A8088383189,S5M,O,,,,
|
||||
200,A8088383190,C0A,S,,,,
|
||||
201,A8088383191,D2V,S,,,,
|
||||
202,A8088389461,DUP0,S,,,,
|
||||
203,A8129009430,B5C,S,,,,
|
||||
204,A8130212104,C8Y,S,,,,
|
||||
205,A8130218285,D0L,S,,,,
|
||||
206,A8132534722,D4U,S,,,,
|
||||
207,A8132543233,D5B,O,,,,
|
||||
208,A8132543303,D5Z,O,,,,
|
||||
209,A8132543712,D6C,-,,,,
|
||||
210,A8132565715,D7G,S,,,,
|
||||
211,A8133696776,E3Q,S,,,,
|
||||
212,A8133703916,E5J,S,,,,
|
||||
213,A8133704162,E5K,-,,,,
|
||||
214,A8133718802,F0T,O,,,,
|
||||
215,A8133728830,F4Z,S,,,,
|
||||
216,A8134836166,F6Q,S,,,,
|
||||
217,A8134836166,F6R,O,,,,
|
||||
218,A8134840666,F6T,-,,,,
|
||||
219,A8134856799,F8B,S,,,,
|
||||
220,A8134896521,F8W,O,,,,
|
||||
221,A8134902324,G0L,-,,,,
|
||||
222,A8134902324,G0T,O,,,,
|
||||
223,A8147586459,M5F,S,,,,
|
||||
224,A8150106844,Q0X,S,,,,
|
||||
225,A8218505828,A9X,-,,,,
|
||||
226,A8218592989,Q0Y,S,,,,
|
||||
227,A8218621069,S1I,O,,,,
|
||||
228,A8219533203,S1R,O,,,,
|
||||
229,A8219534112,S6G,O,,,,
|
||||
230,A8219534112,S6H,O,,,,
|
||||
231,A8219554553,S3A,O,,,,
|
||||
232,A8223795058,L1G,O,,,,
|
||||
233,A8235299888,S8E,S,,,,
|
||||
234,A8236984717,Y4J,S,,,,
|
||||
235,A8236984887,Y4W,-,,,,
|
||||
236,A8238604496,D4N,O,,,,
|
||||
237,A8238806396,E2Y,S,,,,
|
||||
238,A8238822364,E8A,S,,,,
|
||||
239,A8238849646,Q3V,-,,,,
|
||||
240,A8238851748,R0Q,O,,,,
|
||||
241,A8238871437,V5N,-,,,,
|
||||
242,A8240441229,S2B,S,,,,
|
||||
243,A8242038029,Z3H,S,,,,
|
||||
244,A8245325114,X3D,S,,,,
|
||||
245,A8245325114,X3E,-,,,,
|
||||
246,A8247709306,I8R,S,,,,
|
||||
247,A8247710572,IYY,S,,,,
|
||||
248,A8247710818,IZG,S,,,,
|
||||
249,A8249270116,M1U,-,,,,
|
||||
250,A8249270116,M1V,-,,,,
|
||||
251,A8249270116,M1W,-,,,,
|
||||
252,A8249270116,M1X,-,,,,
|
||||
253,A8249270116,M1Y,-,,,,
|
||||
254,A8249270116,M3A,-,,,,
|
||||
255,A8249270116,M3B,-,,,,
|
||||
256,A8249270116,M3C,-,,,,
|
||||
257,A8249270116,M3D,-,,,,
|
||||
258,A8249270116,M3E,S,,,,
|
||||
259,A8249270719,V2B,S,,,,
|
||||
260,A8249270825,V1A,S,,,,
|
||||
261,A8249271073,ZZT,S,,,,
|
||||
262,A8276674900,O5Q,S,,,,
|
||||
263,A8303611888,D0A,O,,,,
|
||||
264,A8387261123,U3W,S,,,,
|
||||
265,A8405138477,F8V,O,,,,
|
||||
266,A8405143036,Z3J,S,,,,
|
||||
267,A8408490681,J8O,S,,,,
|
||||
268,A8408492609,J8Q,S,,,,
|
||||
269,A8469783998,Z4J,-,,,,
|
||||
270,A8486081323,G5L,S,,,,
|
||||
271,A8565145791,U2G,S,,,,
|
||||
272,A8565155034,U2S,S,,,,
|
||||
273,A8583136039,G0K,S,,,,
|
||||
274,A8583148769,U1E,S,,,,
|
||||
275,A8583148769,U1F,O,,,,
|
||||
276,A8583224847,U9Z,S,,,,
|
||||
277,A8620459012,E3W,-,,,,
|
||||
278,A8633749842,S1G,-,,,,
|
||||
279,A8688949972,Z4K,S,,,,
|
||||
280,A8695503860,S2M,O,,,,
|
||||
281,A8718209024,M6E,-,,,,
|
||||
282,A8741776772,C8M,O,,,,
|
||||
283,A8770692605,I8M,S,,,,
|
||||
284,A8770692605,I8N,-,,,,
|
||||
285,A8770692765,I8O,-,,,,
|
||||
286,A8770692765,I8P,S,,,,
|
||||
287,A8827994616,F3Z,-,,,,
|
||||
288,A8833045633,M0C,S,,,,
|
||||
289,MB_2FT,MB_2FT_A42_B64/62/4,-,,,,
|
||||
290,MB_2FT,MB_2FT_A64/62,S,,,,
|
||||
291,MB_2FT,MB_2FT_WT_A64/62,-,,,,
|
||||
292,MB_2FT,MB_2FT_WT_B64/62,-,,,,
|
||||
293,MB_CK,MB_CK_C,S,,,,
|
||||
294,MB_CMF,MB_CMF_C,S,,,,
|
||||
295,MB_CMF,MB_CMF_T,O,,,,
|
||||
296,MB_CMF,MB_CMF_TP,O,,,,
|
||||
297,MB_DO,MB_DO_C,S,,,,
|
||||
298,MB_DO,MB_DO_T,O,,,,
|
||||
299,MB_EF,MB_EF_C,S,,,,
|
||||
300,MB_EF,MB_EF_T_A,O,,,,
|
||||
301,MB_EF,MB_EF_T_B,-,,,,
|
||||
302,MB_EX,MB_EX_C,O,,,,
|
||||
303,MB_EX,MB_EX_ST_A,O,,,,
|
||||
304,MB_EX,MB_EX_T_A,O,,,,
|
||||
305,MB_EX,MB_EX_T_B,-,,,,
|
||||
306,MB_EX,MB_EX_T_B_B1,O,,,,
|
||||
307,MB_FW,MB_FW_JO_6X4/6X2,S,,,,
|
||||
308,MB_LW,MB_LW_A/B_B1,O,,,,
|
||||
309,MB_MT,MB_MT_A/B,O,,,,
|
||||
310,MB_RS,MB_RS_A/B,O,,,,
|
||||
311,MB_SM,MB_SM_A/B,-,,,,
|
||||
312,MB_SW,MB_SW_G70,O,,,,
|
||||
313,MB_SW,MB_SW_G80,O,,,,
|
||||
314,MB_TR,MB_TR_G70_6x4,O,,,,
|
||||
315,MB_TR,MB_TR_G80_6x4,S,,,,
|
||||
316,MB_WT,MB_WT_A_64/62,-,,,,
|
||||
317,MB_WT,MB_WT_B_64/62,-,,,,
|
|
BIN
data/销售配置表.xls
Normal file
BIN
data/销售配置表.xls
Normal file
Binary file not shown.
138
data/销售配置表_约束规则.csv
Normal file
138
data/销售配置表_约束规则.csv
Normal file
@ -0,0 +1,138 @@
|
||||
序号,规则
|
||||
1,M1W=>G1X&Z2H
|
||||
2,AP-B F58MEA 0C=>R8P
|
||||
3,G2B=>G5G
|
||||
4,M3A=>(G2B|G2E)
|
||||
5,M1X=>(G1X&M4A)
|
||||
6,AP-B F58LFA 0C=>R8P
|
||||
7,~(M7I&(D6C))
|
||||
8,J5R=>J6A
|
||||
9,E1N=>Z5E
|
||||
10,S1I=>(B1B&D2E&S1W&S2M&X3D&(G1W|G1X|G5G))
|
||||
11,AP-B V18MEA 0C=>R8P
|
||||
12,AP-B F38MEA 0C=>R8P
|
||||
13,E0D=>(E1K&(D6C|Y1X))
|
||||
14,Q0Y=>(Q0R|Q4K)
|
||||
15,~(E5J&(V5N))
|
||||
16,K7N=>(Z2H|Z5E)
|
||||
17,Z5E=>(M3A|M3B|M3C|M3D|M3E)
|
||||
18,~(D6F&((D6C|D6I|D6M)))
|
||||
19,M6E=>Z2H&(M5D&M7T&(M3A|M3B|M3C))
|
||||
20,Q5U=>(H1J&Q4K&Q4X&Q6D)
|
||||
21,B3J=>(G1W|G1X)
|
||||
22,J2K=>(J5R|J6C)
|
||||
23,AP-B F38MFA 0C=>R8P
|
||||
24,G5L=>G5G
|
||||
25,S1P=>B1U
|
||||
26,Q4X=>(Q5J|Q5U)
|
||||
27,AP-B F58L98 81=>R8P
|
||||
28,X3E=>(M4A|M4B)
|
||||
29,U2G=>Z5E
|
||||
30,I8P=>Z5E
|
||||
31,D6I=>D6M
|
||||
32,~(E1L&((D6C|D6M)))
|
||||
33,J2I=>(J5R|J6C)
|
||||
34,D6C=>(D6G&E0D&E1K)
|
||||
35,M3C=>G2E
|
||||
36,Q0W=>(Q5J|Q5U)
|
||||
37,M1Y=>(G1X&M4A)
|
||||
38,Y1X=>D7J
|
||||
39,K2R=>Z4K
|
||||
40,Q5J=>(H1J&Q0R&Q4X&Q6D)
|
||||
41,Q6D=>(Q5J|Q5U)
|
||||
42,S1W=>B1B
|
||||
43,M6M=>(M5D&Z5E)
|
||||
44,M7T=>Z5E
|
||||
45,G5G=>(G2B|G2E)
|
||||
46,Z4K=>(K2R|K4X|K8M)
|
||||
47,H1J=>(Q5J|Q5U)
|
||||
48,K8N=>(K0W&K8T&Z4R&Z5E)
|
||||
49,~(G1X&(G5G))
|
||||
50,S6H=>B1B
|
||||
51,L1G=>Z5E
|
||||
52,J1H=>J6A
|
||||
53,~(G1W&(G5G))
|
||||
54,M0E=>((M3C&(B3J|G2E))|((M3A|M3B)&(B3J|G2B|G2E)))
|
||||
55,R8P=>R8F
|
||||
56,M3B=>(G1X|G2E)
|
||||
57,D6M=>(D6G&D6I&D7A&E1K)
|
||||
58,U3W=>J6A&Z2H
|
||||
59,S2M=>(B1B&S1W)
|
||||
60,I8M=>Z5E
|
||||
61,K8T=>(Z4R&((K8L&(M4A|M4B))|(K8N&Z5E)))
|
||||
62,Q4K=>Q5U
|
||||
63,K8L=>(K0W&K8T&Z4R&(M4A|M4B))
|
||||
64,R8F=>R8P
|
||||
65,Z5Q=>(G2B|G2E)
|
||||
66,K8M=>Z4K
|
||||
67,S5M=>S1W
|
||||
68,U2S=>U2G
|
||||
69,Z5I=>Z5E
|
||||
70,AP-B F58L96 81=>R8P
|
||||
71,S3A=>(D0A&D2E&X3D)
|
||||
72,I8N=>Z5E
|
||||
73,M3E=>G2E
|
||||
74,G0L=>(G1W|G1X)
|
||||
75,S1G=>(B1B&S1W&S2M&(G1W|G1X))
|
||||
76,M3D=>G2E
|
||||
77,M5V=>(M5D&Z5E)
|
||||
78,M4A=>(M1W|M1X|M1Y)
|
||||
79,G0K=>(Z5E&((B3J&(G1W|G1X))|(G5G&(B3J|G2B|G2E))))
|
||||
80,M1V=>(G1W&M4B)
|
||||
81,Y4Z=>D0S
|
||||
82,Q0R=>Q5J
|
||||
83,S1R=>(B1B&S1W&S2M&Z5E)
|
||||
84,K4X=>(K2R&Z5E)&(K0W&Z4K)
|
||||
85,X3D=>Z5E
|
||||
86,M1U=>(G1W&M4B)
|
||||
87,M4B=>(M1U|M1V)
|
||||
88,M5D=>Z5E
|
||||
89,K0W=>(K4X|K8K|K8L|K8N)
|
||||
90,AP-B V18MFA 0C=>R8P
|
||||
91,I8O=>Z5E
|
||||
92,K8K=>(K0W&K2R&Z4R&(M4A|M4B))
|
||||
93,S6G=>B1B
|
||||
94,G2E=>G5G
|
||||
95,MB_CMF_T=>D4T&D4U&D8L&E2Y&D0A&D4N&D5B&D5Z&D6G&D7J&F3C
|
||||
96,MB_CMF_TP=>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A&E1K&E3W&K8T&F3Z&K8L
|
||||
118,MB_2FT_WT_A64/62=>K0W&K8T&K8N&Z4R
|
||||
119,MB_2FT_WT_B64/62=>K0W&K8T&Z4R&K8L
|
||||
120,MB_CK_C=>J6A&J1H&J5R&J2I&U3W
|
||||
121,MB_2FT_A42_B64/62/4=>K0W&K8K&Z4R
|
||||
122,MB_2FT_A64/62=>K0W&K4X
|
||||
123,MB_CMF_C=>D4T&D4U&D8L&E2Y
|
||||
124,MB_SW_G80=>MB_TR_G80_6x4
|
||||
125,MB_SW_G70=>MB_TR_G70_6x4
|
||||
126,(MB_DO_C|MB_DO_T)=>M7I
|
||||
127,M1X|M3A=>!(B3J|A5D)
|
||||
128,U1F<=>S1W
|
||||
129,C8M&I2E&I2F=>MB_LW_A/B_B1
|
||||
130,MB_CMF_T|MB_CMF_TP=>D2E
|
||||
131,M7I=>!MB_SM_A/B
|
||||
132,G0T=>((G2B|G2E)&G5G)|((G1W|G1X)&B3J)&Z5E
|
||||
133,MB_EX_ST_A=>S1R
|
||||
134,MB_MT_A/B&X3E=>A5D&B3J
|
||||
135,MB_EX_T_A|MB_EX_ST_A|MB_EX_T_B=>MB_CMF_TP|MB_CMF_T|MB_SM_A/B
|
||||
136,MB_EX_T_A|MB_EX_ST_A=>MB_CMF_TP|MB_CMF_T|MB_SM_A/B
|
||||
137,MB_MT_A/B&X3D=>A5D
|
|
BIN
data/销售配置表_约束规则.xls
Normal file
BIN
data/销售配置表_约束规则.xls
Normal file
Binary file not shown.
1
name_nbvar.var
Normal file
1
name_nbvar.var
Normal file
@ -0,0 +1 @@
|
||||
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,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,520,521,522,523,524,525,526,527,528,529,530,531,532,533,534,535,536,537,538,539
|
2089
result.cnf
Normal file
2089
result.cnf
Normal file
File diff suppressed because it is too large
Load Diff
21
src/Allocate.cpp
Normal file
21
src/Allocate.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#include "Allocate.h"
|
||||
|
||||
int IDManager::id = 0;
|
||||
std::map<int, std::string> IDManager::idToName;
|
||||
std::map<std::string, int> IDManager::nameToID;
|
||||
|
||||
|
||||
int IDManager::allocate() {
|
||||
return ++id;
|
||||
}
|
||||
|
||||
int IDManager::getOrAllocate(std::string name) {
|
||||
if(nameToID.count(name))
|
||||
return nameToID[name];
|
||||
int tid = allocate();
|
||||
nameToID[name] = tid;
|
||||
idToName[tid] = name;
|
||||
|
||||
CNF::comment("MAP: " + name + " -> " + std::to_string(tid));
|
||||
return tid;
|
||||
}
|
16
src/Allocate.h
Normal file
16
src/Allocate.h
Normal file
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include "CNF.h"
|
||||
|
||||
class IDManager {
|
||||
public:
|
||||
static int allocate();
|
||||
static int getOrAllocate(std::string name);
|
||||
|
||||
static std::map<int, std::string> idToName;
|
||||
static std::map<std::string, int> nameToID;
|
||||
static int id;
|
||||
};
|
37
src/CNF.cpp
Normal file
37
src/CNF.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include "CNF.h"
|
||||
|
||||
std::vector<std::vector<int>> CNF::vec;
|
||||
std::vector<int> CNF::tmp;
|
||||
std::set<int> CNF::el;
|
||||
std::queue<std::pair<int, std::string>> CNF::cq;
|
||||
|
||||
void CNF::add(int x) {
|
||||
if(x == 0) {
|
||||
vec.push_back(tmp);
|
||||
tmp.clear();
|
||||
} else {
|
||||
el.insert(abs(x));
|
||||
tmp.push_back(x);
|
||||
}
|
||||
}
|
||||
|
||||
void CNF::comment(std::string str) {
|
||||
cq.push(make_pair(vec.size(), str));
|
||||
}
|
||||
|
||||
void CNF::print() {
|
||||
printf("p cnf %d %d\n", IDManager::id, vec.size());
|
||||
|
||||
for(int i=0; i<vec.size(); i++) {
|
||||
|
||||
while(!cq.empty() && i >= cq.front().first) {
|
||||
printf("c %s\n", cq.front().second.c_str());
|
||||
cq.pop();
|
||||
}
|
||||
|
||||
for(auto& lit : vec[i]) {
|
||||
printf("%d ", lit);
|
||||
}
|
||||
printf("0\n");
|
||||
}
|
||||
}
|
22
src/CNF.h
Normal file
22
src/CNF.h
Normal file
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include "Allocate.h"
|
||||
|
||||
class CNF {
|
||||
public:
|
||||
static void add(int x);
|
||||
static void comment(std::string str);
|
||||
static void print();
|
||||
|
||||
private:
|
||||
static std::set<int> el;
|
||||
static std::vector<int> tmp;
|
||||
static std::vector<std::vector<int>> vec;
|
||||
static std::queue<std::pair<int, std::string>> cq;
|
||||
};
|
28
src/Calculator.p
Normal file
28
src/Calculator.p
Normal file
@ -0,0 +1,28 @@
|
||||
term And assoc(left) prec(4); // +
|
||||
term Or assoc(left) prec(3); // -
|
||||
term Entail assoc(left) prec(2); // *
|
||||
term rEntail assoc(left) prec(2); // *
|
||||
term Equal assoc(left) prec(1); // /
|
||||
term Not;
|
||||
term LeftParen; // (
|
||||
term RightParen; // )
|
||||
term LiteralNumber {% Clause %};
|
||||
|
||||
nonterm exp {% Clause %};
|
||||
|
||||
grammar {
|
||||
exp -> LiteralNumber(value) {% return value; %};
|
||||
exp -> LeftParen exp(exp) RightParen {% return exp; %};
|
||||
exp -> Not exp(rhs) prec(10) {% return ~rhs; %};
|
||||
exp -> exp(lhs) And exp(rhs) {% return lhs & rhs; %};
|
||||
exp -> exp(lhs) Or exp(rhs) {% return lhs | rhs; %};
|
||||
exp -> exp(lhs) Entail exp(rhs) {% return (~lhs)|rhs; %};
|
||||
exp -> exp(lhs) rEntail exp(rhs) {% return (~rhs)|lhs; %};
|
||||
exp -> exp(lhs) Equal exp(rhs) {% return ((~lhs)|rhs)&((~rhs)|lhs); %};
|
||||
};
|
||||
|
||||
generator {%
|
||||
{
|
||||
"class_name": "CalculatorParser"
|
||||
}
|
||||
%};
|
344
src/CalculatorParser.cpp
Normal file
344
src/CalculatorParser.cpp
Normal file
@ -0,0 +1,344 @@
|
||||
/**
|
||||
* @file
|
||||
* @date 2022-09-01
|
||||
*
|
||||
* Auto generated code by 9chu/parser_gen.
|
||||
*/
|
||||
#include "CalculatorParser.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
#define ACTION_ERROR 0
|
||||
#define ACTION_ACCEPT 1
|
||||
#define ACTION_GOTO 2
|
||||
#define ACTION_REDUCE 3
|
||||
|
||||
namespace {
|
||||
CalculatorParser::ProductionValues Reduce0(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 1);
|
||||
auto value =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::TokenValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return value; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce1(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto exp =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 2])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return exp; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce2(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 2);
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return ~rhs; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce3(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto lhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 3])
|
||||
)
|
||||
));
|
||||
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return lhs & rhs; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce4(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto lhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 3])
|
||||
)
|
||||
));
|
||||
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return lhs | rhs; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce5(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto lhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 3])
|
||||
)
|
||||
));
|
||||
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return (~lhs)|rhs; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce6(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto lhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 3])
|
||||
)
|
||||
));
|
||||
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return (~rhs)|lhs; }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
CalculatorParser::ProductionValues Reduce7(std::vector<CalculatorParser::UnionValues>& stack_)
|
||||
{
|
||||
// binding values
|
||||
assert(stack_.size() >= 3);
|
||||
auto lhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 3])
|
||||
)
|
||||
));
|
||||
|
||||
auto rhs =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<CalculatorParser::ProductionValues>(
|
||||
std::move(stack_[stack_.size() - 1])
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// user code
|
||||
auto ret = [&]() {
|
||||
return ((~lhs)|rhs)&((~rhs)|lhs); }();
|
||||
return CalculatorParser::ProductionValues { std::move(ret) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
using ReduceFunction = CalculatorParser::ProductionValues(*)(std::vector<CalculatorParser::UnionValues>&);
|
||||
|
||||
struct ProductionInfo
|
||||
{
|
||||
uint32_t NonTerminal;
|
||||
uint32_t SymbolCount;
|
||||
ReduceFunction Callback;
|
||||
};
|
||||
|
||||
struct ActionInfo
|
||||
{
|
||||
uint8_t Action;
|
||||
uint32_t Arg;
|
||||
};
|
||||
|
||||
static const ProductionInfo kProductions[8] = {
|
||||
{ 10, 1, ::Reduce0 },
|
||||
{ 10, 3, ::Reduce1 },
|
||||
{ 10, 2, ::Reduce2 },
|
||||
{ 10, 3, ::Reduce3 },
|
||||
{ 10, 3, ::Reduce4 },
|
||||
{ 10, 3, ::Reduce5 },
|
||||
{ 10, 3, ::Reduce6 },
|
||||
{ 10, 3, ::Reduce7 },
|
||||
};
|
||||
|
||||
static const ActionInfo kActions[34][11] = {
|
||||
{ { 0, 0 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 3 },{ 2, 2 },{ 2, 4 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 1 }, },
|
||||
{ { 1, 0 },{ 2, 8 },{ 2, 7 },{ 2, 9 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 6 },{ 0, 0 },{ 2, 5 },{ 0, 0 }, },
|
||||
{ { 3, 0 },{ 3, 0 },{ 3, 0 },{ 3, 0 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 3, 0 },{ 0, 0 },{ 3, 0 },{ 0, 0 }, },
|
||||
{ { 0, 0 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 12 },{ 2, 11 },{ 2, 13 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 10 }, },
|
||||
{ { 0, 0 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 3 },{ 2, 2 },{ 2, 4 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 14 }, },
|
||||
{ { 0, 0 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 3 },{ 2, 2 },{ 2, 4 },{ 0, 0 },{ 0, 0 },{ 0, 0 },{ 2, 15 }, },
|
||||
{ { 0, 0 },{ 0, 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alculatorParser::ParseResult CalculatorParser::operator()(TokenTypes token, const TokenValues& value)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
assert(!m_stStack.empty());
|
||||
assert(static_cast<uint32_t>(token) < 10);
|
||||
|
||||
const ActionInfo& act = kActions[m_stStack.back()][static_cast<uint32_t>(token)];
|
||||
if (act.Action == ACTION_ACCEPT)
|
||||
{
|
||||
// store the result
|
||||
assert(!m_stValueStack.empty());
|
||||
m_stResult =
|
||||
std::move(std::get<Clause>(
|
||||
std::get<ProductionValues>(std::move(m_stValueStack.back()))
|
||||
));
|
||||
|
||||
Reset();
|
||||
return ParseResult::Accepted;
|
||||
}
|
||||
else if (act.Action == ACTION_ERROR)
|
||||
{
|
||||
Reset();
|
||||
return ParseResult::Rejected;
|
||||
}
|
||||
else if (act.Action == ACTION_GOTO)
|
||||
{
|
||||
m_stStack.push_back(static_cast<uint32_t>(token));
|
||||
m_stStack.push_back(act.Arg);
|
||||
assert(m_stStack.back() < 34);
|
||||
|
||||
m_stValueStack.push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(act.Action == ACTION_REDUCE);
|
||||
assert(act.Arg < 8);
|
||||
|
||||
const ProductionInfo& info = kProductions[act.Arg];
|
||||
auto val = info.Callback(m_stValueStack);
|
||||
|
||||
assert(m_stStack.size() >= info.SymbolCount * 2);
|
||||
m_stStack.resize(m_stStack.size() - info.SymbolCount * 2);
|
||||
|
||||
assert(m_stValueStack.size() >= info.SymbolCount);
|
||||
m_stValueStack.resize(m_stValueStack.size() - info.SymbolCount);
|
||||
|
||||
m_stValueStack.emplace_back(std::move(val));
|
||||
assert(!m_stStack.empty());
|
||||
|
||||
const ActionInfo& act2 = kActions[m_stStack.back()][info.NonTerminal];
|
||||
if (act2.Action == ACTION_GOTO)
|
||||
{
|
||||
m_stStack.push_back(info.NonTerminal);
|
||||
m_stStack.push_back(act2.Arg);
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
Reset();
|
||||
return ParseResult::Rejected;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ParseResult::Undecided;
|
||||
}
|
||||
|
||||
void CalculatorParser::Reset()noexcept
|
||||
{
|
||||
m_stStack.clear();
|
||||
m_stValueStack.clear();
|
||||
|
||||
// initial state
|
||||
m_stStack.push_back(0);
|
||||
}
|
66
src/CalculatorParser.hpp
Normal file
66
src/CalculatorParser.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* @file
|
||||
* @date 2022-09-01
|
||||
*
|
||||
* Auto generated code by 9chu/parser_gen.
|
||||
*/
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
#include "ValueType.hpp"
|
||||
|
||||
|
||||
// namespace {
|
||||
class CalculatorParser
|
||||
{
|
||||
public:
|
||||
enum class ParseResult
|
||||
{
|
||||
Undecided = 0,
|
||||
Accepted = 1,
|
||||
Rejected = 2,
|
||||
};
|
||||
|
||||
enum class TokenTypes
|
||||
{
|
||||
_ = 0,
|
||||
And = 1,
|
||||
Entail = 2,
|
||||
Equal = 3,
|
||||
LeftParen = 4,
|
||||
LiteralNumber = 5,
|
||||
Not = 6,
|
||||
Or = 7,
|
||||
RightParen = 8,
|
||||
rEntail = 9,
|
||||
};
|
||||
|
||||
using TokenValues = std::variant<
|
||||
std::monostate,
|
||||
Clause
|
||||
>;
|
||||
|
||||
using ProductionValues = std::variant<
|
||||
Clause
|
||||
>;
|
||||
|
||||
using UnionValues = std::variant<TokenValues, ProductionValues>;
|
||||
|
||||
public:
|
||||
CalculatorParser();
|
||||
|
||||
public:
|
||||
ParseResult operator()(TokenTypes token, const TokenValues& value);
|
||||
void Reset()noexcept;
|
||||
|
||||
const Clause& Result()const noexcept { return m_stResult; }
|
||||
Clause& Result()noexcept { return m_stResult; }
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> m_stStack;
|
||||
std::vector<UnionValues> m_stValueStack;
|
||||
|
||||
Clause m_stResult {};
|
||||
};
|
||||
// }
|
179
src/Main.cpp
Normal file
179
src/Main.cpp
Normal file
@ -0,0 +1,179 @@
|
||||
#include <tuple>
|
||||
#include <variant>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
#include "ValueType.hpp"
|
||||
#include "CalculatorParser.hpp"
|
||||
#include "rapidcsv.h"
|
||||
#include "Allocate.h"
|
||||
#include "CNF.h"
|
||||
|
||||
class Tokenizer {
|
||||
public:
|
||||
Tokenizer(const char* buffer)
|
||||
: m_pBuffer(buffer) {}
|
||||
public:
|
||||
std::tuple<CalculatorParser::TokenTypes, CalculatorParser::TokenValues> Advance() {
|
||||
using TokenTypes = CalculatorParser::TokenTypes;
|
||||
using TokenValues = CalculatorParser::TokenValues;
|
||||
while (true) {
|
||||
if (*m_pBuffer == '\0')
|
||||
return { TokenTypes::_, TokenValues {} };
|
||||
|
||||
char c;
|
||||
switch (c = *(m_pBuffer++)) {
|
||||
case '&': return { TokenTypes::And, TokenValues {} };
|
||||
case '|': return { TokenTypes::Or, TokenValues {} };
|
||||
case '(': return { TokenTypes::LeftParen, TokenValues {} };
|
||||
case ')': return { TokenTypes::RightParen, TokenValues {} };
|
||||
case '~': return { TokenTypes::Not, TokenValues {} };
|
||||
case '!': return { TokenTypes::Not, TokenValues {} };
|
||||
case '=':
|
||||
c = *(m_pBuffer++);
|
||||
if(c != '>') throw std::runtime_error("Bad input");
|
||||
return { TokenTypes::Entail, TokenValues {} };
|
||||
case '<':
|
||||
c = *(m_pBuffer++);
|
||||
if(c != '=') throw std::runtime_error("Bad input");
|
||||
c = *(m_pBuffer++);
|
||||
if(c != '>') {
|
||||
m_pBuffer--;
|
||||
return { TokenTypes::rEntail, TokenValues {} };
|
||||
}
|
||||
return { TokenTypes::Equal, TokenValues {} };
|
||||
default:
|
||||
std::string str;
|
||||
str += c;
|
||||
while (!isReservedSymbol(*m_pBuffer) && *m_pBuffer != '\0')
|
||||
str = str + *(m_pBuffer++);
|
||||
//std::cout << str << std::endl;
|
||||
Clause clause;
|
||||
clause.positive = true;
|
||||
clause.type = Clause::TYPE::UNIT;
|
||||
clause.vec.push_back(IDManager::getOrAllocate(str));
|
||||
return { TokenTypes::LiteralNumber, TokenValues { clause } };
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
const char* m_pBuffer;
|
||||
bool isReservedSymbol(char c) {
|
||||
return c == '&' || c == '|' || c == '('
|
||||
|| c == ')' || c == '~' || c == '<'
|
||||
|| c == '=' || c == '>' || c == '!';
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
try {
|
||||
rapidcsv::Document doc_1("data/是否必选特征族.csv");
|
||||
std::set<std::string> familyMustChoose;
|
||||
|
||||
for(int i=0; i<doc_1.GetRowCount(); i++) {
|
||||
auto row = doc_1.GetRow<std::string>(i);
|
||||
|
||||
std::string familyName = row[2];
|
||||
std::string value = row[3];
|
||||
|
||||
if(value == "是") {
|
||||
familyMustChoose.insert(familyName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rapidcsv::Document doc_2("data/销售配置表.csv");
|
||||
|
||||
std::map<std::string, std::vector<std::string>> valuesByFamily;
|
||||
std::map<std::string, std::vector<std::string>> valuesByNotForceFamily;
|
||||
|
||||
|
||||
for(int i=0; i<doc_2.GetRowCount(); i++) {
|
||||
auto row = doc_2.GetRow<std::string>(i);
|
||||
|
||||
std::string familyName = row[1];
|
||||
std::string valueName = row[2];
|
||||
std::string chooseFlag = row[3];
|
||||
|
||||
if(chooseFlag == "-") {
|
||||
CNF::add(-IDManager::getOrAllocate(valueName));
|
||||
CNF::add(0);
|
||||
}
|
||||
valuesByFamily[familyName].push_back(valueName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(auto& [family, vec] : valuesByFamily) {
|
||||
if(familyMustChoose.find(family) != familyMustChoose.end()) {
|
||||
for(auto v : vec) {
|
||||
CNF::add(IDManager::getOrAllocate(v));
|
||||
}
|
||||
CNF::add(0);
|
||||
}
|
||||
for(int i=0; i<vec.size(); i++) {
|
||||
for(int j=i+1; j<vec.size(); j++) {
|
||||
CNF::add(-IDManager::getOrAllocate(vec[i]));
|
||||
CNF::add(-IDManager::getOrAllocate(vec[j]));
|
||||
CNF::add(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rapidcsv::Document doc_3("data/销售配置表_约束规则.csv");
|
||||
|
||||
auto constraint = doc_3.GetColumn<std::string>(1);
|
||||
for(auto& str : constraint) {
|
||||
if(str == "") continue;
|
||||
CNF::comment("analyze: " + str);
|
||||
|
||||
Tokenizer tokenizer(str.c_str());
|
||||
CalculatorParser parser;
|
||||
while (true) {
|
||||
auto [t, v] = tokenizer.Advance();
|
||||
|
||||
auto ret = parser(t, v);
|
||||
if (ret == CalculatorParser::ParseResult::Rejected)
|
||||
throw std::runtime_error("Parse error");
|
||||
else if (ret == CalculatorParser::ParseResult::Accepted) {
|
||||
parser.Result().mergeIntoUNIT();
|
||||
CNF::add(parser.Result().vec[0]);
|
||||
CNF::add(0);
|
||||
}
|
||||
|
||||
if (t == CalculatorParser::TokenTypes::_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::set<std::string> list;
|
||||
|
||||
auto inf = doc_2.GetColumn<std::string>(7);
|
||||
|
||||
for(auto& family : inf) {
|
||||
list.insert(family);
|
||||
}
|
||||
|
||||
printf("c ind ");
|
||||
// for(auto& [family, vec] : valuesByFamily) {
|
||||
// //if(list.find(family) != list.end()) continue;
|
||||
// for(auto &v : valuesByFamily[family]) {
|
||||
// printf("%d ", IDManager::getOrAllocate(v));
|
||||
// }
|
||||
// }
|
||||
for(int i=1; i<=539; i++) {
|
||||
printf("%d ", i);
|
||||
}
|
||||
printf("0\n");
|
||||
|
||||
CNF::print();
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
std::cerr << ex.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
109
src/ValueType.hpp
Normal file
109
src/ValueType.hpp
Normal file
@ -0,0 +1,109 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "Allocate.h"
|
||||
#include "CNF.h"
|
||||
|
||||
class Clause {
|
||||
public:
|
||||
enum class TYPE {
|
||||
UNIT = 0,
|
||||
AND = 1,
|
||||
OR = 2,
|
||||
};
|
||||
|
||||
std::vector<int> vec;
|
||||
TYPE type;
|
||||
bool positive;
|
||||
|
||||
Clause(): type() {
|
||||
positive = true;
|
||||
}
|
||||
|
||||
void mergeIntoUNIT() {
|
||||
if(type == TYPE::UNIT) return;
|
||||
|
||||
int newId = IDManager::allocate();
|
||||
|
||||
|
||||
std::string output = "MAP: ";
|
||||
for(int i=0; i<vec.size()-1; i++) {
|
||||
output += std::to_string(vec[i]) + (type == TYPE::AND ? " & " : " | ");
|
||||
}
|
||||
output += std::to_string(vec[vec.size()-1]);
|
||||
output += " -> " + std::to_string(newId);
|
||||
|
||||
CNF::comment(output);
|
||||
|
||||
if(type == TYPE::AND) {
|
||||
CNF::add(newId);
|
||||
for(auto v : vec) {
|
||||
CNF::add(-v);
|
||||
}
|
||||
CNF::add(0);
|
||||
|
||||
for(auto v : vec) {
|
||||
CNF::add(v);
|
||||
CNF::add(-newId);
|
||||
CNF::add(0);
|
||||
}
|
||||
} else {
|
||||
CNF::add(-newId);
|
||||
for(auto v : vec) {
|
||||
CNF::add(v);
|
||||
}
|
||||
CNF::add(0);
|
||||
|
||||
for(auto v : vec) {
|
||||
CNF::add(-v);
|
||||
CNF::add(newId);
|
||||
CNF::add(0);
|
||||
}
|
||||
}
|
||||
|
||||
vec.clear();
|
||||
vec.push_back(newId);
|
||||
type = TYPE::UNIT;
|
||||
}
|
||||
|
||||
|
||||
friend Clause operator ~ (Clause hs) {
|
||||
for(auto it=hs.vec.begin(); it!=hs.vec.end(); it++ ) {
|
||||
*it = -(*it);
|
||||
}
|
||||
|
||||
if(hs.type == TYPE::AND) hs.type = TYPE::OR;
|
||||
else if(hs.type == TYPE::OR) hs.type = TYPE::AND;
|
||||
|
||||
//if(hs.vec.size() == 1 && hs.type != TYPE::UNIT) exit(233);
|
||||
return hs;
|
||||
}
|
||||
|
||||
friend Clause operator & (Clause lhs, Clause rhs) {
|
||||
|
||||
Clause res;
|
||||
res.type = TYPE::AND;
|
||||
|
||||
if(lhs.type == TYPE::OR) lhs.mergeIntoUNIT();
|
||||
if(rhs.type == TYPE::OR) rhs.mergeIntoUNIT();
|
||||
|
||||
for(auto v : lhs.vec) res.vec.push_back(v);
|
||||
for(auto v : rhs.vec) res.vec.push_back(v);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
friend Clause operator | (Clause lhs, Clause rhs) {
|
||||
|
||||
Clause res;
|
||||
res.type = TYPE::OR;
|
||||
|
||||
if(lhs.type == TYPE::AND) lhs.mergeIntoUNIT();
|
||||
if(rhs.type == TYPE::AND) rhs.mergeIntoUNIT();
|
||||
|
||||
for(auto v : lhs.vec) res.vec.push_back(v);
|
||||
for(auto v : rhs.vec) res.vec.push_back(v);
|
||||
|
||||
return res;
|
||||
}
|
||||
};
|
2232
src/parser_gen.py
Normal file
2232
src/parser_gen.py
Normal file
File diff suppressed because it is too large
Load Diff
1800
src/rapidcsv.h
Normal file
1800
src/rapidcsv.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
untitled/.DS_Store
vendored
Normal file
BIN
untitled/.DS_Store
vendored
Normal file
Binary file not shown.
3
untitled/.idea/.gitignore
generated
vendored
Normal file
3
untitled/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
13
untitled/.idea/compiler.xml
generated
Normal file
13
untitled/.idea/compiler.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="untitled" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
7
untitled/.idea/encodings.xml
generated
Normal file
7
untitled/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
20
untitled/.idea/jarRepositories.xml
generated
Normal file
20
untitled/.idea/jarRepositories.xml
generated
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
14
untitled/.idea/misc.xml
generated
Normal file
14
untitled/.idea/misc.xml
generated
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="18" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
25
untitled/pom.xml
Normal file
25
untitled/pom.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.example</groupId>
|
||||
<artifactId>untitled</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.logicng</groupId>
|
||||
<artifactId>logicng</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
2089
untitled/result.cnf
Normal file
2089
untitled/result.cnf
Normal file
File diff suppressed because it is too large
Load Diff
BIN
untitled/src/.DS_Store
vendored
Normal file
BIN
untitled/src/.DS_Store
vendored
Normal file
Binary file not shown.
30
untitled/src/main/java/org/example/Main.java
Normal file
30
untitled/src/main/java/org/example/Main.java
Normal file
@ -0,0 +1,30 @@
|
||||
package org.example;
|
||||
|
||||
import org.logicng.formulas.Formula;
|
||||
import org.logicng.formulas.FormulaFactory;
|
||||
import org.logicng.formulas.Variable;
|
||||
import org.logicng.io.parsers.ParserException;
|
||||
import org.logicng.io.readers.DimacsReader;
|
||||
import org.logicng.modelcounting.ModelCounter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws ParserException, IOException {
|
||||
FormulaFactory f = new FormulaFactory();
|
||||
List<Formula> formulas = DimacsReader.readCNF("result.cnf", f);
|
||||
|
||||
SortedSet<Variable> variables = new TreeSet<>();
|
||||
for(Formula formula : formulas) {
|
||||
variables.addAll(formula.variables());
|
||||
}
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
|
||||
BigInteger modelcount = ModelCounter.count(formulas, variables);
|
||||
System.out.println("answer:" + modelcount);
|
||||
System.out.println("time: " + (System.currentTimeMillis()-time) + " ms");
|
||||
}
|
||||
}
|
BIN
untitled/target/classes/org/example/Main.class
Normal file
BIN
untitled/target/classes/org/example/Main.class
Normal file
Binary file not shown.
BIN
甘棠约束条件编码器.pdf
Normal file
BIN
甘棠约束条件编码器.pdf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user