首页 > 其他分享 >kissat的多输出-学习与修改1

kissat的多输出-学习与修改1

时间:2024-09-11 20:26:17浏览次数:14  
标签:输出 const solver lit 修改 other assigned kissat

学习:传播、回溯、重启

 

//propsearch.h中

定义以下引用标识符

#define PROPAGATE_LITERAL search_propagate_literal
#define PROPAGATION_TYPE "search"

 

 //proplit.h中给出完整传播函数定义——对于了解文字传播队列非常重要

  1 static inline clause *PROPAGATE_LITERAL (kissat *solver,
  2 #if defined(PROBING_PROPAGATION)
  3                                          const clause *const ignore,
  4 #endif
  5                                          const unsigned lit) {
  6   assert (solver->watching);
  7   LOG (PROPAGATION_TYPE " propagating %s", LOGLIT (lit));
  8   assert (VALUE (lit) > 0);
  9   assert (EMPTY_STACK (solver->delayed));
 10 
 11   watches *const all_watches = solver->watches;
 12   ward *const arena = BEGIN_STACK (solver->arena);
 13   assigned *const assigned = solver->assigned;
 14   value *const values = solver->values;
 15 
 16   const unsigned not_lit = NOT (lit);
 17 
 18   assert (not_lit < LITS);
 19   watches *watches = all_watches + not_lit;
 20 
 21   watch *const begin_watches = BEGIN_WATCHES (*watches);
 22   const watch *const end_watches = END_WATCHES (*watches);
 23 
 24   watch *q = begin_watches;
 25   const watch *p = q;
 26 
 27   unsigneds *const delayed = &solver->delayed;
 28   assert (EMPTY_STACK (*delayed));
 29 
 30   const size_t size_watches = SIZE_WATCHES (*watches);
 31   uint64_t ticks = 1 + kissat_cache_lines (size_watches, sizeof (watch));
 32   const unsigned idx = IDX (lit);
 33   struct assigned *const a = assigned + idx;
 34   const bool probing = solver->probing;
 35   const unsigned level = a->level;
 36   clause *res = 0;
 37 
 38   while (p != end_watches) {
 39     const watch head = *q++ = *p++;
 40     const unsigned blocking = head.blocking.lit;
 41     assert (VALID_INTERNAL_LITERAL (blocking));
 42     const value blocking_value = values[blocking];
 43     const bool binary = head.type.binary;
 44     watch tail;
 45     if (!binary)
 46       tail = *q++ = *p++;
 47     if (blocking_value > 0)
 48       continue;
 49     if (binary) {
 50       if (blocking_value < 0) {
 51         res = kissat_binary_conflict (solver, not_lit, blocking);
 52 #ifndef CONTINUE_PROPAGATING_AFTER_CONFLICT
 53         break;
 54 #endif
 55       } else {
 56         assert (!blocking_value);
 57         kissat_fast_binary_assign (solver, probing, level, values, assigned,
 58                                    blocking, not_lit);
 59         ticks++;
 60       }
 61     } else {
 62       const reference ref = tail.raw;
 63       assert (ref < SIZE_STACK (solver->arena));
 64       clause *const c = (clause *) (arena + ref);
 65       ticks++;
 66       if (c->garbage) {
 67         q -= 2;
 68         continue;
 69       }
 70       unsigned *const lits = BEGIN_LITS (c);
 71       const unsigned other = lits[0] ^ lits[1] ^ not_lit;
 72       assert (lits[0] != lits[1]);
 73       assert (VALID_INTERNAL_LITERAL (other));
 74       assert (not_lit != other);
 75       assert (lit != other);
 76       const value other_value = values[other];
 77       if (other_value > 0) {
 78         q[-2].blocking.lit = other;
 79         continue;
 80       }
 81       const unsigned *const end_lits = lits + c->size;
 82       unsigned *const searched = lits + c->searched;
 83       assert (c->lits + 2 <= searched);
 84       assert (searched < end_lits);
 85       unsigned *r, replacement = INVALID_LIT;
 86       value replacement_value = -1;
 87       for (r = searched; r != end_lits; r++) {
 88         replacement = *r;
 89         assert (VALID_INTERNAL_LITERAL (replacement));
 90         replacement_value = values[replacement];
 91         if (replacement_value >= 0)
 92           break;
 93       }
 94       if (replacement_value < 0) {
 95         for (r = lits + 2; r != searched; r++) {
 96           replacement = *r;
 97           assert (VALID_INTERNAL_LITERAL (replacement));
 98           replacement_value = values[replacement];
 99           if (replacement_value >= 0)
100             break;
101         }
102       }
103 
104       if (replacement_value >= 0) {
105         c->searched = r - lits;
106         assert (replacement != INVALID_LIT);
107         LOGREF3 (ref, "unwatching %s in", LOGLIT (not_lit));
108         q -= 2;
109         lits[0] = other;
110         lits[1] = replacement;
111         assert (lits[0] != lits[1]);
112         *r = not_lit;
113         kissat_delay_watching_large (solver, delayed, replacement, other,
114                                      ref);
115         ticks++;
116       } else if (other_value) {
117         assert (replacement_value < 0);
118         assert (blocking_value < 0);
119         assert (other_value < 0);
120 #if defined(PROBING_PROPAGATION)
121         if (c == ignore) {
122           LOGREF (ref, "conflicting but ignored");
123           continue;
124         }
125 #endif
126         LOGREF (ref, "conflicting");
127         res = c;
128 #ifndef CONTINUE_PROPAGATING_AFTER_CONFLICT
129         break;
130 #endif
131       } else {
132         assert (replacement_value < 0);
133 #if defined(PROBING_PROPAGATION)
134         if (c == ignore) {
135           LOGREF (ref, "forcing %s but ignored", LOGLIT (other));
136           continue;
137         }
138 #endif
139         kissat_fast_assign_reference (solver, values, assigned, other, ref,
140                                       c);
141         ticks++;
142       }
143     }
144   }
145   solver->ticks += ticks;
146 
147   while (p != end_watches)
148     *q++ = *p++;
149   SET_END_OF_WATCHES (*watches, q);
150 
151   kissat_watch_large_delayed (solver, all_watches, delayed);
152 
153   return res;
154 }

 

 

 

函数kissat_fast_assign_reference

---------- D:\SAT_study2024\kissat-sc2024-d776b9e1\src\fastassign.h
[27] kissat_fast_assign_reference (kissat *solver, value *values,

---------- D:\SAT_study2024\kissat-sc2024-d776b9e1\src\propdense.c
[75] kissat_fast_assign_reference (solver, values, assigned, unit, ref,

---------- D:\SAT_study2024\kissat-sc2024-d776b9e1\src\proplit.h
[172] kissat_fast_assign_reference (solver, values, assigned, other, ref,

 

 

//fastassign.h

 1 #ifndef _fastassign_h_INCLUDED
 2 #define _fastassign_h_INCLUDED
 3 
 4 #define FAST_ASSIGN
 5 
 6 #include "inline.h"
 7 #include "inlineassign.h"
 8 
 9 static inline void kissat_fast_binary_assign (
10     kissat *solver, const bool probing, const unsigned level, value *values,
11     assigned *assigned, unsigned lit, unsigned other) {
12   if (GET_OPTION (jumpreasons) && level && solver->classification.bigbig) {
13     unsigned other_idx = IDX (other);
14     struct assigned *a = assigned + other_idx;
15     if (a->binary) {
16       LOGBINARY (lit, other, "jumping %s reason", LOGLIT (lit));
17       INC (jumped_reasons);
18       other = a->reason;
19     }
20   }
21   kissat_fast_assign (solver, probing, level, values, assigned, true, lit,
22                       other);
23   LOGBINARY (lit, other, "assign %s reason", LOGLIT (lit));
24 }
25 
26 static inline void
27 kissat_fast_assign_reference (kissat *solver, value *values,
28                               assigned *assigned, unsigned lit,
29                               reference ref, clause *reason) {
30   assert (reason == kissat_dereference_clause (solver, ref));
31   const unsigned level =
32       kissat_assignment_level (solver, values, assigned, lit, reason);
33   assert (level <= solver->level);
34   assert (ref != DECISION_REASON);
35   assert (ref != UNIT_REASON);
36   kissat_fast_assign (solver, solver->probing, level, values, assigned,
37                       false, lit, ref);
38   LOGREF (ref, "assign %s reason", LOGLIT (lit));
39 }
40 
41 #endif

 

 

//inlineassign.h

#define kissat_assign kissat_fast_assign

 

//inlineassign.h完整代码

  1 #ifndef _inlineassign_h_INLCUDED
  2 #define _inlineassign_h_INLCUDED
  3 
  4 #ifdef FAST_ASSIGN
  5 #define kissat_assign kissat_fast_assign
  6 #endif
  7 
  8 static inline void kissat_assign (kissat *solver, const bool probing,
  9                                   const unsigned level,
 10 #ifdef FAST_ASSIGN
 11                                   value *values, assigned *assigned,
 12 #endif
 13                                   bool binary, unsigned lit,
 14                                   unsigned reason) {
 15   const unsigned not_lit = NOT (lit);
 16 
 17   watches watches = WATCHES (not_lit);
 18   if (!kissat_empty_vector (&watches)) {
 19     watch *w = BEGIN_WATCHES (watches);
 20     __builtin_prefetch (w, 0, 1);
 21   }
 22 
 23 #ifndef FAST_ASSIGN
 24   value *values = solver->values;
 25 #endif
 26   assert (!values[lit]);
 27   assert (!values[not_lit]);
 28 
 29   values[lit] = 1;
 30   values[not_lit] = -1;
 31 
 32   assert (solver->unassigned > 0);
 33   solver->unassigned--;
 34 
 35   if (!level) {
 36     kissat_mark_fixed_literal (solver, lit);
 37     assert (solver->unflushed < UINT_MAX);
 38     solver->unflushed++;
 39     if (reason != UNIT_REASON) {
 40       CHECK_AND_ADD_UNIT (lit);
 41       ADD_UNIT_TO_PROOF (lit);
 42       reason = UNIT_REASON;
 43       binary = false;
 44     }
 45   }
 46 
 47   const size_t trail = SIZE_ARRAY (solver->trail);
 48   PUSH_ARRAY (solver->trail, lit);
 49 
 50   const unsigned idx = IDX (lit);
 51 
 52 #if !defined(PROBING_PROPAGATION)
 53   if (!probing) {
 54     const bool negated = NEGATED (lit);
 55     const value new_value = BOOL_TO_VALUE (negated);
 56     value *saved = &SAVED (idx);
 57     *saved = new_value;
 58   }
 59 #endif
 60 
 61   struct assigned b;
 62 
 63   b.level = level;
 64   b.trail = trail;
 65 
 66   b.analyzed = false;
 67   b.binary = binary;
 68   b.poisoned = false;
 69   b.reason = reason;
 70   b.removable = false;
 71   b.shrinkable = false;
 72 
 73 #ifndef FAST_ASSIGN
 74   assigned *assigned = solver->assigned;
 75 #endif
 76   struct assigned *a = assigned + idx;
 77   *a = b;
 78 }
 79 
 80 static inline unsigned
 81 kissat_assignment_level (kissat *solver, value *values, assigned *assigned,
 82                          unsigned lit, clause *reason) {
 83   unsigned res = 0;
 84   for (all_literals_in_clause (other, reason)) {
 85     if (other == lit)
 86       continue;
 87     assert (values[other] < 0), (void) values;
 88     const unsigned other_idx = IDX (other);
 89     struct assigned *a = assigned + other_idx;
 90     const unsigned level = a->level;
 91     if (res < level)
 92       res = level;
 93   }
 94 #ifdef NDEBUG
 95   (void) solver;
 96 #endif
 97   return res;
 98 }
 99 
100 #endif

 

 

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

 

标签:输出,const,solver,lit,修改,other,assigned,kissat
From: https://www.cnblogs.com/yuweng1689/p/18408904

相关文章

  • 自写一个植物大战僵尸修改器
    这也是学习游戏安全的一部分(确信主要是体会一下游戏里面的各种数据修改大概是个什么样子。先拿这个比较ez的练练手,后面写点更有趣的(指fps的挂希望写出来不是屎山游戏版本:Plantsvs.ZombiesGOTYEdition(steam的这玩意也没更新过吧获取进程id和基址这一步和游戏本身暂......
  • 修改docker的默认存储位置及镜像存储位置
    前言Docker默认安装的情况下,会使用/var/lib/docker/目录作为存储目录,用以存放拉取的镜像和创建的容器等。不过由于此目录一般都位于系统盘,遇到系统盘比较小,而镜像和容器多了后就容易出问题,这里说明一下如何修改Docker的默认存储目录。一、查看当前docker的默认存储目录do......
  • windowns 修改RDP端口
    命令行操作$portvalue=13389#修改注册表Set-ItemProperty-Path'HKLM:\SYSTEM\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp'-name"PortNumber"-Value$portvalue#添加防火墙规则New-NetFirewallRule-DisplayName'RDPPORTL......
  • 5. 在源码里修改lan的默认IP
    参考网友帖子:OpenWrt编译时修改默认IP地址-OpenWrt中文教程&More(jwtechtips.top)修改如下文件openwrt/imx_openwrt/package/base-files/files/binconfig_generate如下:case"$protocol"instatic)localipadcase"$1"in......
  • 在Navicat中对postgre数据库批量修改表的Owner
     navicat中可以在General中看到Owner的信息,需要修改某个表的Owner时,可以在设计表的Options选项中修改  但是表比较多的时候不太方便,可以使用sql命令来修改:select'ALTERTABLE'||table_name||'OWNERTOtargetOwner;'frominformation_schema.tableswhereta......
  • 22级五年制C语言入门教程-(5)格式化输入输出
    1.输入和输出在程序的使用中,我们经常可以看的这么一个场景:用户需要输入数据,经过程序运算,得到结果后输出。在C语言中,输入数据和输出数据都是由库函数完成的,通过语句来输入/输出。2.格式化输出—printf()函数C语言程序运算的结果在内存中,我们需要将其输出到指定设备中,我们才可以......
  • VD1013 DFN小封装芯片 适用于小电流的输出的电池保护芯片
            VD1013内置高精度电压检测电路和延迟电路以及内置MOSFET,是用于单节锂离子/锂聚合物可再充电电池的保护IC。        本IC适合于对1节锂离子/锂聚合物可再充电电池的过充电、过放电和过电流进行保护   。VD1013具备如下特点:高精度电压检测电路......
  • 黑暗之魂 I&#038;II 合集,豪华中文,重制最终版-灭绝深渊-原罪学者+全DLC+修改器,解压即
    游戏截图《黑暗之魂I&II合集》是一款由FromSoftware开发的经典动作角色扮演游戏合集,囊括了《黑暗之魂》系列的前两部作品:《黑暗之魂:重制版》和《黑暗之魂II:原罪学者》。该合集为玩家提供了进入深邃而神秘的黑暗奇幻世界的机会,体验系列标志性的高难度战斗和复杂的叙事设......
  • 【生日视频制作】直升机飞机侧身AE模板修改文字软件生成器教程特效素材【AE模板】
    生日视频制作教程直升机飞机侧身AE模板修改文字特效广告生成神器素材祝福玩法AE模板工程AE模板套用改图文教程↓↓:怎么如何做的【生日视频制作】直升机飞机侧身AE模板修改文字软件生成器教程特效素材【AE模板】生日视频制作步骤:下载AE模板安装AE软件把AE模板导入......
  • 记一次Fidder Script自动修改包
    FiddlerScript的本质是用JScript.NET编写的一个脚本文件CustomRules.js但是它的语法很像C#但又有些不一样,比如不能使用@符号通过修改CustomRules.js可以灵活修改请求报文和响应报文,也无需中断程序。同时也可以利用它针对不同的URL做各种特殊处理。Fiddler安装时已经自带了Fidd......