Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/TakehideSoh/SAF
18 January 2026, 11:53:51 UTC
  • Code
  • Branches (4)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/dev
    • refs/heads/main
    • refs/tags/v1.0-cmsb2023
    • refs/tags/v1.1-CMSB2023
    No releases to show
  • 5153fb6
  • /
  • cadical
  • /
  • src
  • /
  • instantiate.cpp
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:9f3785a847c99dda87b31c5ae943c8d4c9ea38cd
origin badgedirectory badge
swh:1:dir:01d80ce94d8f49344a6b25660f682eedd134ff96
origin badgerevision badge
swh:1:rev:3b45819df15225431050eeb48c1a31ffdd580af7
origin badgesnapshot badge
swh:1:snp:d3fcf0e446f52630e867f11dee4c2c828bf46951

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 3b45819df15225431050eeb48c1a31ffdd580af7 authored by Daniel Le Berre on 22 June 2023, 20:02:19 UTC
Typo in README
Tip revision: 3b45819
instantiate.cpp
#include "internal.hpp"

namespace CaDiCaL {

/*------------------------------------------------------------------------*/

// This provides an implementation of variable instantiation, a technique
// for removing literals with few occurrence (see also 'instantiate.hpp').

/*------------------------------------------------------------------------*/

// Triggered at the end of a variable elimination round ('elim_round').

void
Internal::collect_instantiation_candidates (Instantiator & instantiator) {
  assert (occurring ());
  for (auto idx : vars) {
    if (frozen (idx)) continue;
    if (!active (idx)) continue;
    if (flags (idx).elim) continue;               // BVE attempt pending
    for (int sign = -1; sign <= 1; sign += 2) {
      const int lit = sign * idx;
      if (noccs (lit) > opts.instantiateocclim) continue;
      Occs & os = occs (lit);
      for (const auto & c : os) {
        if (c->garbage) continue;
        if (opts.instantiateonce && c->instantiated) continue;
        if (c->size < opts.instantiateclslim) continue;
        bool satisfied = false;
        int unassigned = 0;
        for (const auto & other : *c) {
          const signed char tmp = val (other);
          if (tmp > 0) satisfied = true;
          if (!tmp) unassigned++;
        }
        if (satisfied) continue;
        if (unassigned < 3) continue;           // avoid learning units
        size_t negoccs = occs (-lit).size ();
        LOG (c,
          "instantiation candidate literal %d "
          "with %zu negative occurrences in", lit, negoccs);
        instantiator.candidate (lit, c, c->size, negoccs);
      }
    }
  }
}

/*------------------------------------------------------------------------*/

// Specialized propagation and assignment routines for instantiation.

inline void Internal::inst_assign (int lit) {
  LOG ("instantiate assign %d", lit);
  assert (!val (lit));
  vals[lit] = 1;
  vals[-lit] = -1;
  trail.push_back (lit);
}

bool Internal::inst_propagate () {      // Adapted from 'propagate'.
  START (propagate);
  int64_t before = propagated;
  bool ok = true;
  while (ok && propagated != trail.size ()) {
    const int lit = -trail[propagated++];
    LOG ("instantiate propagating %d", -lit);
    Watches & ws = watches (lit);
    const const_watch_iterator eow = ws.end ();
    const_watch_iterator i = ws.begin ();
    watch_iterator j = ws.begin ();
    while (i != eow) {
      const Watch w = *j++ = *i++;
      const signed char b = val (w.blit);
      if (b > 0) continue;
      if (w.binary ()) {
        if (b < 0) { ok = false; LOG (w.clause, "conflict"); break; }
        else inst_assign (w.blit);
      } else {
        literal_iterator lits = w.clause->begin ();
        const int other = lits[0]^lits[1]^lit;
        lits[0] = other, lits[1] = lit;
        const signed char u = val (other);
        if (u > 0) j[-1].blit = other;
        else {
          const int size = w.clause->size;
          const const_literal_iterator end = lits + size;
          const literal_iterator middle = lits + w.clause->pos;
          literal_iterator k = middle;
          signed char v = -1;
          int r = 0;
          while (k != end && (v = val (r = *k)) < 0)
            k++;
          if (v < 0) {
            k = lits + 2;
            assert (w.clause->pos <= size);
            while (k != middle && (v = val (r = *k)) < 0)
              k++;
          }
          w.clause->pos = k - lits;
          assert (lits + 2 <= k), assert (k <= w.clause->end ());
          if (v > 0) {
            j[-1].blit = r;
          } else if (!v) {
            LOG (w.clause, "unwatch %d in", r);
            lits[1] = r;
            *k = lit;
            watch_literal (r, lit, w.clause);
            j--;
          } else if (!u) {
            assert (v < 0);
            inst_assign (other);
          } else {
            assert (u < 0);
            assert (v < 0);
            LOG (w.clause, "conflict");
            ok = false;
            break;
          }
        }
      }
    }
    if (j != i) {
      while (i != eow)
        *j++ = *i++;
      ws.resize (j - ws.begin ());
    }
  }
  int64_t delta = propagated - before;
  stats.propagations.instantiate += delta;
  STOP (propagate);
  return ok;
}

/*------------------------------------------------------------------------*/

// This is the actual instantiation attempt.

bool Internal::instantiate_candidate (int lit, Clause * c) {
  stats.instried++;
  if (c->garbage) return false;
  assert (!level);
  bool found = false, satisfied = false, inactive = false;
  int unassigned = 0;
  for (const auto & other : *c) {
    if (other == lit) found = true;
    const signed char tmp = val (other);
    if (tmp > 0) { satisfied = true; break; }
    if (!tmp && !active (other)) { inactive = true; break; }
    if (!tmp) unassigned++;
  }
  if (!found) return false;
  if (inactive) return false;
  if (satisfied) return false;
  if (unassigned < 3) return false;
  size_t before = trail.size ();
  assert (propagated == before);
  assert (active (lit));
  LOG (c, "trying to instantiate %d in", lit);
  assert (!c->garbage);
  c->instantiated = true;
  level++;
  inst_assign (lit);                            // Assume 'lit' to true.
  for (const auto & other : *c) {
    if (other == lit) continue;
    const signed char tmp = val (other);
    if (tmp) { assert (tmp < 0); continue; }
    inst_assign (-other);                       // Assume other to false.
  }
  bool ok = inst_propagate ();                  // Propagate.
  while (trail.size () > before) {              // Backtrack.
    const int other = trail.back ();
    LOG ("instantiate unassign %d", other);
    trail.pop_back ();
    assert (val (other) > 0);
    vals[other] = vals[-other] = 0;
  }
  propagated = before;
  assert (level == 1);
  level = 0;
  if (ok) { LOG ("instantiation failed"); return false; }
  unwatch_clause (c);
  strengthen_clause (c, lit);
  watch_clause (c);
  assert (c->size > 1);
  LOG ("instantiation succeeded");
  stats.instantiated++;
  return true;
}

/*------------------------------------------------------------------------*/

// Try to instantiate all candidates collected before through the
// 'collect_instantiation_candidates' routine.

void Internal::instantiate (Instantiator & instantiator) {
  assert (opts.instantiate);
  START (instantiate);
  stats.instrounds++;
#ifndef QUIET
  const int64_t candidates = instantiator.candidates.size ();
#endif
  int64_t instantiated = 0, tried = 0;
  init_watches ();
  connect_watches ();
  if (propagated < trail.size ()) {
    if (!propagate ()) {
      LOG ("propagation after connecting watches failed");
      learn_empty_clause ();
      assert (unsat);
    }
  }
  PHASE ("instantiate", stats.instrounds,
    "attempting to instantiate %" PRId64 " candidate literal clause pairs",
    candidates);
  while (!unsat &&
         !terminated_asynchronously () &&
         !instantiator.candidates.empty ()) {
    Instantiator::Candidate cand = instantiator.candidates.back ();
    instantiator.candidates.pop_back ();
    tried++;
    if (!active (cand.lit)) continue;
    LOG (cand.clause,
      "trying to instantiate %d with "
      "%zd negative occurrences in", cand.lit, cand.negoccs);
    if (!instantiate_candidate (cand.lit, cand.clause)) continue;
    instantiated++;
    VERBOSE (2, "instantiation %" PRId64 " (%.1f%%) succeeded "
      "(%.1f%%) with %zd negative occurrences in size %d clause",
      tried, percent (tried, candidates),
      percent (instantiated, tried), cand.negoccs, cand.size);
  }
  PHASE ("instantiate", stats.instrounds,
    "instantiated %" PRId64 " candidate successfully "
    "out of %" PRId64 " tried %.1f%%",
    instantiated, tried, percent (instantiated, tried));
  report ('I', !instantiated);
  reset_watches ();
  STOP (instantiate);
}

}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API