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

  • a8ef816
  • /
  • resources
  • /
  • comssextractor_ng
  • /
  • cmp
  • /
  • utils
  • /
  • wcnf.h
Raw File Download

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
content badge
swh:1:cnt:5db90dd368ae406f0ba184cc383fb68ffe568e6c
directory badge
swh:1:dir:79d57efab63ef256061b76ed45bf35fdbfaeb737

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
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
wcnf.h
#ifndef WCNF_H
#define WCNF_H

#include <vector>
#include "cmp/utils/cmpTypes.h"
#include "cmp/utils/Sort.h"

using namespace std;

namespace CMP {

  struct Sft_Clause
  {
    int ID;
    vector<Lit> lits;
  };
  
  class WCNF {
    vector< vector<Lit> > hard_clauses;
    vector<Sft_Clause> soft_clauses;
    int n_vars;

  public:
    WCNF():n_vars(0) {}
    ~WCNF(){}

    inline void newVar(void) {n_vars++;}
    inline void addHard(vector<Lit> lits) {hard_clauses.push_back(lits);}
    inline void addSoft(vector<Lit> lits, int id) {soft_clauses.push_back((Sft_Clause){id,lits});}

    inline void addHard(vec<Lit>& ps) {
      vector<Lit> lits;
      for(int i=0; i<ps.size(); i++) lits.push_back(ps[i]);
      hard_clauses.push_back(lits);
    }
    
    inline void addSoft(vec<Lit>& ps, int id) {
      vector<Lit> lits;
      sort(ps);
      Lit p;
      int i;
      for(i=0, p = lit_Undef; i<ps.size(); i++) {
	if(ps[i] != p) {p = ps[i]; lits.push_back(ps[i]);} //remove duplicate literals
      }
      soft_clauses.push_back((Sft_Clause){id,lits});
    }

    
    inline int nVars(void) {return n_vars;}
    inline int nSofts(void) {return soft_clauses.size();}
    inline int nHards(void) {return hard_clauses.size();}
    inline int nClauses(void) {return hard_clauses.size()+soft_clauses.size();}

    inline int getSoft_ID(size_t i) {return soft_clauses[i].ID;}
  
    inline const vector<Lit>& getSoft(size_t i) {return soft_clauses[i].lits;}
    inline const vector<Lit>& getHard(size_t i) {return hard_clauses[i];}
    
    inline void getSoft(int i, vec<Lit>& ps) {
      ps.clear(); for(size_t j=0; j<soft_clauses[i].lits.size(); j++) ps.push(soft_clauses[i].lits[j]);
    }
    
    inline void getHard(int i, vec<Lit>& ps) {
      ps.clear(); for(size_t j=0; j<hard_clauses[i].size(); j++) ps.push(hard_clauses[i][j]);
    }

    inline void output() {
      printf("\np wcnf %d %d %d\n",nVars(), nHards()+nSofts(), nSofts()+1);
      for(int i=0; i<nHards(); i++){
	printf("%d ",nSofts()+1);
	for(size_t j=0; j<getHard(i).size(); j++) printf("%c%d ", sign(getHard(i)[j])?'-':' ', var(getHard(i)[j])+1);
	printf("0\n");
      }
      for(int i=0; i<nSofts(); i++){
 	printf("1 ");
	for(size_t j=0; j<getSoft(i).size(); j++) printf("%c%d ", sign(getSoft(i)[j])?'-':' ', var(getSoft(i)[j])+1);
	printf("0\n");
      }
      printf("\n");
    }

     inline void printSoft(int i) {
      printf("1 ");
      for(size_t j=0; j<getSoft(i).size(); j++) printf("%c%d ", sign(getSoft(i)[j])?'-':' ', var(getSoft(i)[j])+1);
      printf("0\n");
    }

     inline void printHard(int i) {
       printf("%d ",nSofts()+1);
       for(size_t j=0; j<getHard(i).size(); j++) printf("%c%d ", sign(getHard(i)[j])?'-':' ', var(getHard(i)[j])+1);
       printf("0\n");
     }
	
  };

}//namespace

#endif

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