首页 > 其他分享 >kissat分析02_主要功能函数01_propagate

kissat分析02_主要功能函数01_propagate

时间:2023-05-03 14:34:37浏览次数:49  
标签:02 lit 01 solver value assert other propagate kissat

传播函数分布在propsearch.h、propsearch.c和proplit.c文件之中

  propsearch.h
 
#ifndef _propsearch_h_INCLUDED
#define _propsearch_h_INCLUDED

struct kissat;
struct clause;

struct clause *kissat_search_propagate (struct kissat *);

#endif

 

   

 

  propsearch.c
 
#define INLINE_ASSIGN

#include "inline.h"
#include "propsearch.h"
#include "bump.h"

// Keep this 'inlined' file separate:

#include "assign.c"

#define PROPAGATE_LITERAL search_propagate_literal
#define PROPAGATION_TYPE "search"

#include "proplit.h"

static inline void
update_search_propagation_statistics (kissat * solver,
                      unsigned previous_propagated_level)
{
  assert (previous_propagated_level <= solver->propagated);
  const unsigned propagated = solver->propagated - previous_propagated_level;

  LOG ("propagation took %" PRIu64 " propagations", propagated);
  LOG ("propagation took %" PRIu64 " ticks", solver->ticks);

  ADD (propagations, propagated);
  ADD (ticks, solver->ticks);

  ADD (search_propagations, propagated);
  ADD (search_ticks, solver->ticks);

  if (solver->stable)
    {
      ADD (stable_propagations, propagated);
      ADD (stable_ticks, solver->ticks);
    }
  else
    {
      ADD (focused_propagations, propagated);
      ADD (focused_ticks, solver->ticks);
    }
}

static inline void
update_consistently_assigned (kissat * solver)
{
  const unsigned assigned = kissat_assigned (solver);
  if (assigned != solver->consistently_assigned)
    {
      LOG ("updating consistently assigned from %u to %u",
       solver->consistently_assigned, assigned);
      solver->consistently_assigned = assigned;
    }
  else
    LOG ("keeping consistently assigned %u", assigned);
}

static clause *
search_propagate (kissat * solver)
{
  clause *res = 0;
  while (!res && solver->propagated < SIZE_STACK (solver->trail))
    {
      const unsigned lit = PEEK_STACK (solver->trail, solver->propagated);
      res = search_propagate_literal (solver, lit);
      solver->propagated++;
    }
  return res;
}




clause *
kissat_search_propagate (kissat * solver)
{
  assert (!solver->probing);
  assert (solver->watching);
  assert (!solver->inconsistent);

  START (propagate);

  solver->ticks = 0;
  const unsigned propagated = solver->propagated;
  clause *conflict = search_propagate (solver);
  update_search_propagation_statistics (solver, propagated);
  update_consistently_assigned (solver);
  if (conflict)
    INC (conflicts);
  STOP (propagate);

  // CHB
  if(solver->stable && solver->heuristic==1){
      int i = SIZE_STACK (solver->trail) - 1;
      unsigned lit = i>=0?PEEK_STACK (solver->trail, i):0;  
      while(i>=0 && LEVEL(lit)==solver->level){
        lit = PEEK_STACK (solver->trail, i);
            kissat_bump_chb(solver,IDX(lit), conflict? 1.0 : 0.9); 
        i--;        
      }
  }  
  if(solver->stable && solver->heuristic==1 && conflict) kissat_decay_chb(solver);

  return conflict;
}

 

   

 

  proplit.c
 
  1 static inline clause *
  2 PROPAGATE_LITERAL (kissat * solver,
  3 #if defined(HYPER_PROPAGATION) || defined(PROBING_PROPAGATION)
  4            const clause * ignore,
  5 #endif
  6            const unsigned lit)
  7 {
  8   assert (solver->watching);
  9   LOG (PROPAGATION_TYPE " propagating %s", LOGLIT (lit));
 10   assert (VALUE (lit) > 0);
 11   assert (EMPTY_STACK (solver->delayed));
 12 
 13   const word *arena = BEGIN_STACK (solver->arena);
 14   assigned *assigned = solver->assigned;
 15   value *values = solver->values;
 16 
 17   const unsigned not_lit = NOT (lit);
 18 #ifdef HYPER_PROPAGATION
 19   const bool hyper = GET_OPTION (hyper);
 20 #endif
 21   watches *watches = &WATCHES (not_lit);
 22   watch *begin_watches = BEGIN_WATCHES (*watches), *q = begin_watches;
 23   const watch *end_watches = END_WATCHES (*watches), *p = q;
 24   unsigneds *delayed = &solver->delayed;
 25 
 26   uint64_t ticks = kissat_cache_lines (watches->size, sizeof (watch));
 27 
 28   clause *res = 0;
 29 
 30   while (p != end_watches)
 31     {
 32       const watch head = *q++ = *p++;
 33       const unsigned blocking = head.blocking.lit;
 34       assert (VALID_INTERNAL_LITERAL (blocking));
 35       const value blocking_value = values[blocking];
 36       if (head.type.binary)
 37     {
 38       if (blocking_value > 0)
 39         continue;
 40       const bool redundant = head.binary.redundant;
 41       if (blocking_value < 0)
 42         {
 43           res = kissat_binary_conflict (solver, redundant,
 44                         not_lit, blocking);
 45           break;
 46         }
 47       else
 48         {
 49           assert (!blocking_value);
 50           kissat_assign_binary (solver, values, assigned,
 51                     redundant, blocking, not_lit);
 52         }
 53     }
 54       else
 55     {
 56       const watch tail = *q++ = *p++;
 57       if (blocking_value > 0)
 58         continue;
 59       const reference ref = tail.raw;
 60       assert (ref < SIZE_STACK (solver->arena));
 61       clause *c = (clause *) (arena + ref);
 62 #if defined(HYPER_PROPAGATION) || defined(PROBING_PROPAGATION)
 63       if (c == ignore)
 64         continue;
 65 #endif
 66       ticks++;
 67       if (c->garbage)
 68         {
 69           q -= 2;
 70           continue;
 71         }
 72       unsigned *lits = BEGIN_LITS (c);
 73       const unsigned other = lits[0] ^ lits[1] ^ not_lit;
 74       assert (lits[0] != lits[1]);
 75       assert (VALID_INTERNAL_LITERAL (other));
 76       assert (not_lit != other);
 77       assert (lit != other);
 78       const value other_value = values[other];
 79       if (other_value > 0)
 80         q[-2].blocking.lit = other;
 81       else
 82         {
 83           const unsigned *end_lits = lits + c->size;
 84           unsigned *searched = lits + c->searched;
 85           assert (c->lits + 2 <= searched);
 86           assert (searched < end_lits);
 87           unsigned *r, replacement = INVALID_LIT;
 88           value replacement_value = -1;
 89           for (r = searched; r != end_lits; r++)
 90         {
 91           replacement = *r;
 92           assert (VALID_INTERNAL_LITERAL (replacement));
 93           replacement_value = values[replacement];
 94           if (replacement_value >= 0)
 95             break;
 96         }
 97           if (replacement_value < 0)
 98         {
 99           for (r = lits + 2; r != searched; r++)
100             {
101               replacement = *r;
102               assert (VALID_INTERNAL_LITERAL (replacement));
103               replacement_value = values[replacement];
104               if (replacement_value >= 0)
105             break;
106             }
107         }
108 
109           if (replacement_value >= 0)
110         c->searched = r - c->lits;
111 
112           if (replacement_value > 0)
113         {
114           assert (replacement != INVALID_LIT);
115           q[-2].blocking.lit = replacement;
116         }
117           else if (!replacement_value)
118         {
119           assert (replacement != INVALID_LIT);
120           LOGREF (ref, "unwatching %s in", LOGLIT (not_lit));
121           q -= 2;
122           lits[0] = other;
123           lits[1] = replacement;
124           assert (lits[0] != lits[1]);
125           *r = not_lit;
126           kissat_delay_watching_large (solver, delayed,
127                            replacement, other, ref);
128           ticks++;
129         }
130           else if (other_value)
131         {
132           assert (replacement_value < 0);
133           assert (blocking_value < 0);
134           assert (other_value < 0);
135           LOGREF (ref, "conflicting");
136           res = c;
137           break;
138         }
139 #ifdef HYPER_PROPAGATION
140           else if (hyper)
141         {
142           assert (replacement_value < 0);
143           unsigned dom = kissat_find_dominator (solver, other, c);
144           if (dom != INVALID_LIT)
145             {
146               LOGBINARY (dom, other, "hyper binary resolvent");
147 
148               INC (hyper_binary_resolved);
149               INC (clauses_added);
150 
151               INC (hyper_binaries);
152               INC (clauses_redundant);
153 
154               CHECK_AND_ADD_BINARY (dom, other);
155               ADD_BINARY_TO_PROOF (dom, other);
156 
157               kissat_assign_binary (solver, values, assigned,
158                         true, other, dom);
159 
160               delay_watching_hyper (solver, delayed, dom, other);
161               delay_watching_hyper (solver, delayed, other, dom);
162 
163               kissat_delay_watching_large (solver, delayed,
164                            not_lit, other, ref);
165 
166               LOGREF (ref, "unwatching %s in", LOGLIT (not_lit));
167               q -= 2;
168             }
169           else
170             kissat_assign_reference (solver, values,
171                          assigned, other, ref, c);
172         }
173 #endif
174           else
175         {
176           assert (replacement_value < 0);
177           kissat_assign_reference (solver, values,
178                        assigned, other, ref, c);
179         }
180         }
181     }
182     }
183   solver->ticks += ticks;
184 
185   while (p != end_watches)
186     *q++ = *p++;
187   SET_END_OF_WATCHES (*watches, q);
188 
189 #ifdef HYPER_PROPAGATION
190   watch_hyper_delayed (solver, delayed);
191 #else
192   kissat_watch_large_delayed (solver, delayed);
193 #endif
194 
195   return res;
196 }

 

   

 

标签:02,lit,01,solver,value,assert,other,propagate,kissat
From: https://www.cnblogs.com/yuweng1689/p/17369022.html

相关文章

  • [ACTF新生赛2020]easyre 1
    下载回来后,有两个文件查那个内存大的就行,上边那个扔着不管就行查壳32位,进IDA,老套路,进主函数int__cdeclmain(intargc,constchar**argv,constchar**envp){_BYTEv4[12];//[esp+12h][ebp-2Eh]BYREF_DWORDv5[3];//[esp+1Eh][ebp-22h]_BYTEv6[5];//......
  • IDEA2022.1.2(转载)
    安装&破解的时间:2022-09-011.下载IDEA下载地址:https://www.jetbrains.com/idea/download/other.html选择版本:2022.1.2选择绿色版:2022.1.2-WindowsZIPArchive(zip)解压到自定义目录:D:\dev_tools\IntelliJ\ideaIU-2022.1.2.win2.下载破解包下载地址:https://wwi.lanzou......
  • kissat分析01_基本数据结构02_solver
    solver在internal.h中定义下面从使用的角度来了解solver个主要数据成员 assign.c中几个函数 staticinlinevoidkissat_assign(kissat*solver,#ifdefINLINE_ASSIGNvalue*values,assigned*assigned,#endifunsignedlit,......
  • P4211 [LNOI2014]LCA
    \(\color{purple}\text{P4211[LNOI2014]LCA}\)解题方法可以发现一个结论:两个点到根节点的重合路径的长度即为他们\(LCA\)的深度。所以我们把\([l,r]\)之间的点到根节点路径上各加一,再查询\(z\)到根节点的路径的值之和即为\(\sum_{i=l}^{r}\text{dep}[\text{LCA}(i,z)]\)......
  • 2022CVPR_Toward Fast, Flexible, and Robust Low-Light Image Enhancement(SCI_main)
    1.motivation(1)低光增强不能处理复杂的场景(2)需要耗费大量的计算2.contribution(1)节省计算(2)发明了自监督的SCI模块(SCI的核心是引入额外的网络模块(自校准照明)来辅助训练,而不是用于测试)大佬链接:(11条消息)低照度增强--论文阅读【《TowardFast,Flexible,andRobustLow-Light......
  • STAT3010统计方法
    STAT3010/6075StatisticalMethodsinInsuranceAssignment2 Thisassignmentisworth10%oftheoverallmarkforSTAT3010/6075. Thedeadlineforsubmissionis16.00onThursday4May2023. StandardUniversitypoliciesandprocedureswillbefollowedforla......
  • 20230429 模拟赛(jnxxhzz)
    T1.神奇零食柜略,oj上交要加快读T2.防御工事数据范围:\(1\len,m\le100\)不难想到是网络流(虽然我没想到……)这是一个挺基础的网络流对于每个\(V\),我们将它们连到一个超级源点上在往它的四个方向分别建边最后把所有的\(M\)连到一个汇点上而在建边时注意其实\(E->E\)的边......
  • Win11系统,VS2022编写数据库程序,小体积,绿色单文件,支持密码保护,XP到Win11都能运行
    在WIN11中用VS2022编写小体积的绿色单文件,支持密码保护,XP到WIN11都能运行的数据库程序1.用VC60建立一个Win32工程,VC60建立的工程默认是字节型的。2.用VS2010读取并转换为2010格式,再用VS2022读取,选择SDK和平台都不升级3.把wxsqlite3-4.5.1.zip\wxsqlite3-4.5.1\sqlite3se......
  • VS2022使用ClickOnce发布程序本地安装.net框架
    因为遇到下面的错误,没有在网上搜到详细解决问题的教程,费了一些时间才解决了问题,特此记录一下,也希望能帮助到其他人。 要在“系统必备”对话框中启用“从与我的应用程序相同的位置下载系统必备组件”,必须将“.NET桌面运行时6.0.14(x64)”项的文件“net6desktopruntime_x64\win......
  • 2023.5.1——软件工程日报
    所花时间(包括上课):0h代码量(行):0行博客量(篇):1篇今天,数学建模比赛中。。。我了解到的知识点:数学建模的相关知识......