samer_veith.py
def encode_cardinality_sat(self, bound, variables):
        """Enforces cardinality constraints. Cardinality of 2-D structure variables must not exceed bound"""
        # Counter works like this: ctr[i][j][0] states that an arc from i to j exists
        # These are then summed up incrementally edge by edge

        # Define counter variables ctr[i][j][l] with 1 <= i <= n, 1 <= j < n, 1 <= l <= min(j, bound)
        ctr = [[[self._add_var()
                 for _ in range(0, min(j, bound))]
                # j has range 0 to n-1. use 1 to n, otherwise the innermost number of elements is wrong
                for j in range(1, len(variables[0]))]
               for _ in range(0, len(variables))]

        for i in range(0, len(variables)):
            for j in range(1, len(variables[i]) - 1):
                # Ensure that the counter never decrements, i.e. ensure carry over
                for ln in range(0, min(len(ctr[i][j-1]), bound)):
                    self._add_clause(-ctr[i][j - 1][ln], ctr[i][j][ln])

                # Increment counter for each arc
                for ln in range(1, min(len(ctr[i][j]), bound)):
                    self._add_clause(-variables[i][j], -ctr[i][j-1][ln-1], ctr[i][j][ln])

        # Ensure that counter is initialized on the first arc
        for i in range(0, len(variables)):
            for j in range(0, len(variables[i]) - 1):
                self._add_clause(-variables[i][j], ctr[i][j][0])

        # Conflict if target is exceeded
        for i in range(0, len(variables)):
            for j in range(bound, len(variables[i])):
                # Since we start to count from 0, bound - 2
                self._add_clause(-variables[i][j], -ctr[i][j-1][bound - 1])
Enforces cardinality constraints. Cardinality of 2-D structure variables must not exceed bound
Enforces cardinality constraints. Cardinality of 2-D structure variables must not exceed bound
Enforces cardinality constraints . Cardinality of 2 - D structure variables must not exceed bound
def encode_cardinality_sat(self, bound, variables):
        ctr = [[[self._add_var()
                 for _ in range(0, min(j, bound))]
                for j in range(1, len(variables[0]))]
               for _ in range(0, len(variables))]
        for i in range(0, len(variables)):
            for j in range(1, len(variables[i]) - 1):
                for ln in range(0, min(len(ctr[i][j-1]), bound)):
                    self._add_clause(-ctr[i][j - 1][ln], ctr[i][j][ln])
                for ln in range(1, min(len(ctr[i][j]), bound)):
                    self._add_clause(-variables[i][j], -ctr[i][j-1][ln-1], ctr[i][j][ln])
        for i in range(0, len(variables)):
            for j in range(0, len(variables[i]) - 1):
                self._add_clause(-variables[i][j], ctr[i][j][0])
        for i in range(0, len(variables)):
            for j in range(bound, len(variables[i])):
                self._add_clause(-variables[i][j], -ctr[i][j-1][bound - 1])
def encode_cardinality_sat ( self , bound , variables ) : ctr = [ [ [ self . _add_var ( ) for _ in range ( 0 , min ( j , bound ) ) ] for j in range ( 1 , len ( variables [ 0 ] ) ) ] for _ in range ( 0 , len ( variables ) ) ] for i in range ( 0 , len ( variables ) ) : for j in range ( 1 , len ( variables [ i ] ) - 1 ) : for ln in range ( 0 , min ( len ( ctr [ i ] [ j - 1 ] ) , bound ) ) : self . _add_clause ( - ctr [ i ] [ j - 1 ] [ ln ] , ctr [ i ] [ j ] [ ln ] ) for ln in range ( 1 , min ( len ( ctr [ i ] [ j ] ) , bound ) ) : self . _add_clause ( - variables [ i ] [ j ] , - ctr [ i ] [ j - 1 ] [ ln - 1 ] , ctr [ i ] [ j ] [ ln ] ) for i in range ( 0 , len ( variables ) ) : for j in range ( 0 , len ( variables [ i ] ) - 1 ) : self . _add_clause ( - variables [ i ] [ j ] , ctr [ i ] [ j ] [ 0 ] ) for i in range ( 0 , len ( variables ) ) : for j in range ( bound , len ( variables [ i ] ) ) : self . _add_clause ( - variables [ i ] [ j ] , - ctr [ i ] [ j - 1 ] [ bound - 1 ] )
Enforces cardinality constraints.
Enforces cardinality constraints .
"""Enforces cardinality constraints. Cardinality of 2-D structure variables must not exceed bound""" # Counter works like this: ctr[i][j][0] states that an arc from i to j exists # These are then summed up incrementally edge by edge # Define counter variables ctr[i][j][l] with 1 <= i <= n, 1 <= j < n, 1 <= l <= min(j, bound) # j has range 0 to n-1. use 1 to n, otherwise the innermost number of elements is wrong # Ensure that the counter never decrements, i.e. ensure carry over # Increment counter for each arc # Ensure that counter is initialized on the first arc # Conflict if target is exceeded # Since we start to count from 0, bound - 2
self
bound
variables