1.1 Constraint Satisfaction Problems
The homomorphism problem for relational structures is a fundamental computer science problem: Given two relational structures and over the same signature, the goal is to determine the existence of a homomorphism from to (see, e.g., the book by Hell and Nešetřil on this topic ). The homomorphism problem is known to be equivalent to the evaluation problem and the containment problem for conjunctive database queries [12, 37], and also to the constraint satisfaction problem (CSP) 
, which originated in artificial intelligence and provides a common framework for expressing a wide range of both theoretical and real-life combinatorial problems.
For a class of relational structures, we denote by CSP(, ) the restriction of the homomorphism problem in which the input structure belongs to and the input structure is arbitrary (these types of restrictions are known as structural restrictions). Similarly, by CSP(, ) we denote the restriction of the homomorphism problem in which the input structure is arbitrary and the input structure belongs to .
Feder and Vardi initiated the study of CSP(, ), also known as non-uniform CSPs, and famously conjectured that, for every fixed finite structure , either CSP(, ) is in PTIME or CSP(, ) is NP-complete. For example, if is a clique on vertices then CSP(, ) is the well-known -colouring problem, which is known to be in PTIME for and NP-complete for . Most of the progress on the Feder-Vardi conjecture (e.g., [6, 3, 36, 10, 2]) is based on the algebraic approach , culminating in two recent (affirmative) solutions to the Feder-Vardi conjecture obtained independently by Bulatov  and Zhuk .
Note that CSP(, ) is only interesting if is an infinite class of structures as otherwise CSP(, ) is always in PTIME. (This is, however, not the case for CSP(, ) as we have seen in the example of -colouring.) Freuder observed that CSP(, ) is in PTIME if consists of trees  or, more generally, if it has bounded treewidth . Later, Dalmau, Kolaitis, and Vardi showed that CSP(, ) is solved by -consistency, a fundamental local propagation algorithm , if is of bounded treewidth modulo homomorphic equivalence, i.e., if the treewidth of the cores of the structures from is at most , for some fixed . Atserias, Bulatov, and Dalmau showed that this is precisely the class of structures solved by -consistency . In , Grohe proved that the tractability result of Dalmau et al.  is optimal for classes of bounded arity: Under the assumption that FPT W, CSP(, ) is tractable if and only if has bounded treewidth modulo homomorphic equivalence.
1.2 General-valued Constraint Satisfaction Problems
General-valued Constraint Satisfaction Problems (VCSPs) are generalisations of CSPs which allow for not only decision problems but also for optimisation problems (and the mix of the two) to be considered in one framework . In the case of VCSPs we deal with valued structures. Regarding tractable restrictions, the situation of the non-uniform case is by now well-understood. Indeed, assuming the (now proved) Feder-Vardi conjecture, it holds that for any fixed valued structure , either VCSP(, ) is in PTIME or VCSP(, ) is NP-complete [41, 39].
For structural restrictions, it is a folklore result that VCSP(, ) is tractable if is of bounded treewidth; see, e.g. . So is the fact that the -st level of the Sherali-Adams LP hierarchy  solves VCSP(, ) to optimality if the treewidth of all structures in is at most . (We are not aware of any reference for this fact. For certain special problems, it is discussed in . For the extension complexity of such problems, see .) However, unlike the CSP case, the precise borderline of polynomial-time solvability and the power of fundamental algorithms (such as the Sherali-Adams LP hierarchy) for VCSP(, ) is still unknown. Understanding these complexity and algorithmic frontiers for VCSP(, ) is the main goal of this paper.
We study the problem VCSP(, ) for classes of valued structures and give three main results.
(1) Complexity classification
As our first result, we give (in Theorem 19) a complete complexity classification of VCSP(, ) and identify the precise borderline of tractability, for classes of bounded arity. A key ingredient in our result is a novel notion of valued equivalence and a characterisation of this notion in terms of valued cores. More precisely, we show that VCSP(, ) is tractable if and only if has bounded treewidth modulo valued equivalence. This latter notion strictly generalises bounded treewidth and it is strictly weaker than bounded treewidth modulo homomorphic equivalence. Our proof builds on the characterisation by Dalmau et al.  and Grohe  for CSPs. We show that the newly identified tractable classes are solvable by the Sherali-Adams LP hierarchy.
(2) Power of Sherali-Adams
Our second result (Theorem 29) gives a precise characterisation of the power of Sherali-Adams for VCSP(, ). In particular, we show that the -st level of the Sherali-Adams LP hierarchy solves VCSP(, ) to optimality if and only if the valued cores of the structures from have treewidth modulo scopes at most and the overlaps of scopes are of size at most . The proof builds on the work of Atserias et al.  and Thapper and Živný , as well as on an adaptation of the classical result connecting treewidth and brambles by Seymour and Thomas .
(3) Search VCSP
Our first two results are for the VCSP in which we ask for the cost of an optimal solution. It is also possible to define the VCSP as a search problem, in which one is additionally required to return a solution with the optimal cost. A complete characterisation of tractable search cases in terms of structural properties of (a class of structures) is open even for CSPs and there is some evidence that the tractability frontier cannot be captured in simple terms.111In particular, [8, Lemma 1] shows that a description of tractable cases of SCSP(, ), which is the search variant of CSP(, ) defined in Section 6, would imply a description of tractable cases of CSP(, ). Building on our first two results as well as on techniques from , we give in Section 6 a characterisation of the tractable cases for search VCSP(, ) in terms of tractable core computation (Theorem 41).
(4) Additional results
In addition to our main results, we provide in Section 7 tight complexity bounds for several problems related to our classification results, e.g., deciding whether the treewidth is at most modulo valued equivalence, deciding solvability by the -th level of the Sherali-Adams LP hierarchy, and deciding valued equivalence for valued structures. These results have interesting consequences to database theory, specifically, to the evaluation and optimisation of conjunctive queries over annotated databases. In particular, we show that the containment problem of conjunctive queries over the tropical semiring is in NP, thus improving on the work of , which put it in .
1.4 Related work
In his PhD thesis , Färnqvist studied the complexity of VCSP(, ) and also some fragments of VCSPs (see also [22, 20]). He considered a very specific framework that only allows for particular types of classes
’s to be classified. For these classes, he showed that only bounded treewidth gives rise to tractability (assuming bounded arity) and asked about more general classes. In particular, decision CSPs donot fit in his framework and Grohe’s classification  is not implied by Färnqvist’s work. In contrast, our characterisation (of all classes ’s of valued structures) gives rise to new tractable cases going beyond those identified by Färnqvist. Moreover, we can derive both Grohe’s classification and Färnqvist’s classification directly from our results, as explained in Section 4.
It is known that Grohe’s characterisation applies only to classes of bounded arity, i.e., when the arities of the signatures are always bounded by a constant (for instance, CSPs over digraphs) and fails for classes of unbounded arity. In this direction, several hypergraph-based restrictions that lead to tractability have been proposed (for a survey see, e.g. ). Nevertheless, the precise tractability frontier for CSP(, ) is not known. The situation is different for fixed-parameter tractability: Marx gave a complete classification of the fixed-parameter tractable restrictions CSP(, ), for classes of structures of unbounded arity . In the case of VCSPs, Gottlob et al.  and Färnqvist  applied well-known hypergraph-based tractable restrictions of CSPs to VCSPs.
We assume familiarity with relational structures and homomorphisms. Briefly, a relational signature is a finite set of relation symbols , each with a specified arity . A relational structure over a relational signature (or a relational -structure, for short) is a finite universe together with one relation for each symbol . A homomorphism from a relational -structure (with universe ) to a relational -structure (with universe ) is a mapping such that for all and all tuples we have . We refer the reader to  for more details.
We use to denote the set of nonnegative rational numbers with positive infinity, i.e. . As usual, we assume that for all , , and , for all .
A signature is a finite set of function symbols , each with a specified arity . A valued structure over a signature (or valued -structure, for short) is a finite universe together with one function for each symbol . We define to be the set of all pairs such that and . The set of positive tuples of is defined by . If are valued structures, then denote their respective universes.
For simplicity we assume a straightforward table encoding for valued structures, which means that the interpretation of a symbol in a valued structure is encoded as a collection of triples . However, it follows directly from our proofs that the exact same results hold for the more compact positive encoding, which represents by the set . In particular, the size of a valued -structure is roughly
where denotes a reasonable encoding for elements . (For instance, we can encode as a sequence of two nonnegative integers and , with the convention that if and only if .)
We define Valued Constraint Satisfaction Problems (VCSPs) as in . An instance of the VCSP is given by two valued structures and over the same signature . For a mapping , we define
The goal is to find the minimum cost over all possible mappings . We denote this cost by .
For a class of valued structures (not necessarily over the same signature), we denote by VCSP(, ) the class of VCSP instances such that . We say that VCSP(, ) is in PTIME, the class of problems solvable in polynomial time, if there is a deterministic algorithm that solves any instance of VCSP(, ) in time . We also consider the parameterised version of VCSP(, ), denoted by -VCSP(, ), where the parameter is . We say that -VCSP(, ) is in FPT, the class of problems that are fixed-parameter tractable, if there is a deterministic algorithm that solves any instance of -VCSP(, ) in time , where is an arbitrary computable function. The class W, introduced in , can be seen as an analogue of NP in parameterised complexity theory. Proving W-hardness of -VCSP(, ) (under an fpt-reduction, formally defined in Section 4.1) is a strong indication that -VCSP(, ) is not in FPT as it is believed that FPT W. We refer the reader to  for more details on parameterised complexity.
Treewidth of a valued structure
The notion of treewidth (originally introduced by Bertelé and Brioschi  and later rediscovered by Robertson and Seymour ) is a well-known measure of the tree-likeness of a graph . Let be a graph. A tree decomposition of is a pair where is a tree and is a function that maps each node to a subset of such that
for every , the set induces a connected subgraph of , and
for every edge , there is a node with .
The width of the decomposition is . The treewidth of a graph is the minimum width over all its tree decompositions.
Let be a relational structure over relational signature . Its Gaifman graph (also known as primal graph), denoted by , is the graph whose vertex set is the universe of and whose edges are the pairs for which there is a tuple and a relation symbol such that appear in and . We define the treewidth of to be .
Let be a valued -structure. Note that if is the left-hand side of an instance of the VCSP, the only tuples relevant to the problem are those in . Hence, in order to define structural restrictions and in particular, the notion of treewidth, we focus on the structure induced by . Formally, we associate with the signature a relational signature that contains, for every , a relation symbol of the same arity as . We define to be the relational structure over with the same universe of such that if and only if . We let the treewidth of be .
Observe that, in the VCSP, we allow infinite costs not only in but also in the left-hand side structure . This allows us to consider the VCSP as the minimum-cost mapping problem between two mathematical objects of the same nature. Intuitively, mapping the tuples of to infinity ensures that those are logically equivalent to hard constraints, as any minimum-cost solution must map them to tuples of cost exactly in . Thus, decision CSPs, which are -valued VCSPs, are a special case of our definition and all our results also apply to CSPs.
3 Equivalence for valued structures
We start by introducing the notion of valued equivalence that is crucial for our results.
Let be valued -structures. We say that improves , denoted by , if for all valued -structures .
When two valued structures improve each other, we call them equivalent. (In Section 1, we used the term “valued equivalence”. In the rest of the paper, we drop the word “valued” unless needed for clarity.)
Let be valued -structures. We say that and are equivalent, denoted by , if and .
Hence, two valued -structures and are equivalent if they have the same optimal cost over all right-hand side valued structures. Observe that equivalence implies homomorphic equivalence of and . Indeed, whenever is not homomorphic to , we can define a valued -structure as follows: and have the same universe , and for every and , if , and otherwise. Note that (as the identity mapping has cost ), but , and hence, . As the following example shows, the converse does not hold in general.
Consider the valued -structures and from Figure 1, with , where and are binary and unary function symbols, respectively. In Figure 1, is represented by the numbers labelling the nodes, and is represented as follows: pairs receiving cost are depicted as edges, while all remaining pairs are mapped to . Observe that and are homomorphically equivalent. However, they are not (valued) equivalent. Indeed, consider the valued -structure with same universe as such that (i) for every , if , otherwise , and (ii) . It follows that and , and thus .
In the rest of the section, we give characterisations of equivalence in terms of certain types of homomorphisms and (valued) cores. We conclude with a useful characterisation of bounded treewidth modulo equivalence in terms of cores. In order to keep the flow uninterrupted, we defer some of the proofs from this section to Appendix A.
3.1 Inverse fractional homomorphisms
A homomorphism between two relational structures is a structure-preserving mapping. A fractional homomorphism between two valued structures played an important role in 
. Intuitively, it is a probability distribution over mappings between the universes of the two structures with the property that the expected cost is not increased. In this paper, we will need a different but related notion of inverse fractional homomorphism. For sets and , we denote by the set of all mappings from to .
Let be valued -structures. An inverse fractional homomorphism from to is a function with such that for each we have
where . We define the support of to be the set .
The following result relates improvement and inverse fractional homomorphisms. The proof is based on Farkas’ Lemma.
Let be valued -structures. Then, if and only if there exists an inverse fractional homomorphism from to .
Let us remark that an inverse fractional homomorphism from to is actually a distribution over the set of homomorphisms from to , i.e., every is a homomorphism from to . Indeed, for every , where and , it must be the case that . Hence, . In view of Proposition 6, this offers another explanation of the fact that equivalence implies homomorphic equivalence (of the positive parts).
Appropriate notions of cores have played an important role in the complexity classifications of left-hand side restricted CSPs , right-hand side restricted CSPs [9, 7, 52], and right-hand side restricted VCSPs [50, 39]. In this paper, we will define cores around inverse fractional homomorphisms. The proofs of some of the propositions are deferred to the appendix.
For two valued -structures and , we say that that an inverse fractional homomorphism from to is surjective if every is surjective.
A valued -structure is a core if every inverse fractional homomorphism from to is surjective.
Next we show that equivalent valued structure that are cores are in fact isomorphic.
Let be valued -structures. An isomorphism from to is a bijective mapping such that for all . If such an exists, we say that and are isomorphic.
If , are core valued -structures such that , then and are isomorphic.
We now introduce the central notion of a core of a valued structure and show that every valued structure has a unique core (up to isomorphism). In order to do so, we need to state some properties of inverse fractional homomorphisms. The next proposition highlights a key property shared by all mappings that belong to the support of an inverse fractional homomorphism from a valued structure to itself: for every right-hand side valued structure , the composition of and a minimum-cost mapping from to is always a minimum-cost mapping from to .
Let be a valued -structure and be a mapping. Suppose there exists an inverse fractional homomorphism from to such that . Then, for every valued -structure and mapping such that , .
Next we introduce the “image valued structure” of , where is a mapping from a valued structure to itself. When belongs to a inverse fractional homomorphism from to itself, Proposition 10 allows us to show that and the image of are actually equivalent.
Let be a valued -structure, and be a mapping. We define to be the valued -structure over universe such that , for all and .
Let be a valued -structure and be a mapping. Suppose there exists an inverse fractional homomorphism from to such that . Then, .
Now we are ready to define cores and prove their existence.
Let be valued -structures. We say that is a core of if is a core and .
Every valued structure has a core and all cores of are isomorphic. Moreover, for a given valued structure , it is possible to effectively compute a core of and all cores of are over a universe of size at most .
Let be a valued structure. To see that there is always a core for , we can argue inductively. If is a core itself we are done. Otherwise, there is a non-surjective mapping for some inverse fractional homomorphism from to itself. By Proposition 12, . If is core we are done. Otherwise, we repeat the process. As in each step the size of the universe strictly decreases, at some point we reach a valued structure that is a core, and in particular, a valued structure that is a core of . Uniqueness follows directly from Proposition 9. From the argument described above, it follows that the universe of any core of has size at most , and also that we can compute a core from
, as each step in the above-mentioned process is computable. Indeed, by solving a suitable linear program, it is possible to decide whether a valued structure is a core, and in the negative case, compute a non-surjective mappingfor some inverse fractional homomorphism from the valued structure to itself (see Appendix A.5 for a detailed proof). ∎
Proposition 14 allows us to speak about the core of a valued structure. It follows then that equivalence can be characterised in terms of cores: and are equivalent if and only if their cores are isomorphic.
We conclude with a technical characterisation of the property of being a core that will be important in the paper. Intuitively, it states that every non-surjective mapping from a core to itself is suboptimal with respect to a fixed weighting of the tuples of .
Let be a valued -structure. Then, is a core if and only if there exists a mapping such that for every non-surjective mapping ,
Moreover, such a mapping is computable, whenever is a core.
Let and be the valued -structures depicted in Figure 1. Recall that , where is a -valued binary function (represented by edges) and is unary (represented by node labels). Also, the elements of are denoted by , where and indicate the corresponding row and column of the grid, respectively (for readability, only is depicted in Figure 1). We claim that is the core of . Indeed, since is a relational core, it follows that is a core. To see that , let be the mapping that maps all elements in the -th diagonal of (first diagonal is , second diagonal is , and so on) to . Assigning gives an inverse fractional homomorphism from to , and thus by Proposition 6.
Conversely, consider the mappings ,,,,, from to that map to , , , , and , respectively. We define the distribution , , , , and . Then, we have
and hence for all , . It follows that is an inverse fractional homomorphism from to . Therefore, and is the core of . In particular, is not a core. As we explain later in Example 23, it is possible to modify (more precisely, ) so that it becomes a core.
3.3 Treewidth modulo equivalence
In this section we show an elementary property of cores that is crucial for our purposes: the treewidth of the core of a valued structure is the lowest possible among all structures equivalent to .
Let be a valued -structure and be its core. Then, .
Since treewidth is preserved under relational substructures, it suffices to show that is a substructure of , i.e., there is an injective homomorphism from to . Let and be inverse fractional homomorphisms from to , and from to , respectively. Pick any mapping . As observed at the end of Section 3.1, has to be a homomorphism from to . It suffices to show that is injective. Towards a contradiction, suppose is not injective and define as
Observe that is an inverse fractional homomorphism from to . Pick any . It follows that is not injective and . In particular, is not surjective. This contradicts the fact that is a core. ∎
We conclude Section 3 with the following useful characterisation of “being equivalent to a bounded treewidth structure” in terms of cores.
Let be a valued -structure and . Then, the following are equivalent:
There is a valued -structure such that and has treewidth at most .
The treewidth of the core of is at most .
4 Complexity of Vcsp(, )
Let be a class of valued structures. We say that has bounded arity if there is a constant such that for every valued -structure and , we have that . Similarly, we say that has bounded treewidth modulo equivalence if there is a constant such that every is equivalent to a valued structure with . The following is our first main result.
Theorem 19 (Complexity classification).
Assume FPT W. Let be a recursively enumerable class of valued structures of bounded arity. Then, the following are equivalent:
VCSP(, ) is in PTIME.
-VCSP(, ) is in FPT.
has bounded treewidth modulo equivalence.
Although Grohe’s result  for CSPs looks almost identical to Theorem 19, we emphasise that his result involves a different type of equivalence. In Grohe’s case, the equivalence in question is homomorphic equivalence whereas in our case the equivalence in question involves improvement (cf. Definition 3). As we will explain later in this section, Grohe’s classification follows as a special case of Theorem 19.
Note that by Proposition 18, a class has bounded treewidth modulo equivalence if and only if the class given by the cores of the valued structures in has bounded treewidth. This notion strictly generalises bounded treewidth, as illustrated in Example 22. Consequently, Theorem 19 gives new tractable cases.
Consider the signature , where and are binary and unary function symbols, respectively. For , let be the valued -structure with universe such that (i) if , , and ; otherwise , and (ii) , for all . Also, for , let be the valued -structure with universe such that (i) if ; otherwise , and (ii) , for , and , for . The structures and from Figure 1 correspond to and , respectively; informally is a crisp directed grid of size with a unary function with weight applied to each element. Generalising the reasoning behind Example 16, we argue in Appendix B that for each the valued structure is the core of . Since , the class has bounded treewidth modulo equivalence. However, has unbounded treewidth as the Gaifman graphs in correspond to the class of (undirected) grids, which is a well-known family of graphs with unbounded treewidth (see, e.g. ). We also describe in Appendix B how to alter the definition of to obtain a class of finite-valued structures (taking on finite values in ) that has bounded treewidth modulo equivalence but Gaifman graphs of unbounded treewidth.
It is worth noticing that bounded treewidth modulo equivalence implies bounded treewidth modulo homomorphic equivalence (of the positive parts), but the converse is not true in general, as the next example shows. Therefore, Theorem 19 tells us that the tractability frontier for VCSP(, ) lies strictly between bounded treewidth and bounded treewidth modulo homomorphic equivalence.
For , let be the valued -structure from Example 22. Let be the valued -structure with the same universe as , i.e., , such that and is defined as follows. Let be the first diagonals of starting from the bottom left corner (see Figure 2 for an illustration of ). For , let be the top-left to bottom-right enumeration of . In particular, , , and . Fix an integer such that . The values assigned by to , and are , and , respectively, and for , with , is . All remaining elements in receive cost . Figure 2 depicts the case of .
Let . Note first that is homomorphically equivalent to the relational structure over relational signature (recall the definition of from Section 2), whose universe is , and . Since , for all , it follows that has bounded treewidth modulo homomorphic equivalence. We claim that has unbounded treewidth modulo (valued) equivalence. It suffices to show that is a core, for all . In order to prove this, we apply Proposition 15. Fix and define such that (i) if ; otherwise , and (ii) , for all . Note that . Next we show that if satisfies that , then is the identity mapping. Using Proposition 15, this implies that is a core.
Let such that . The mapping must satisfy the following two conditions: (a) is a homomorphism from to (otherwise ), and (b) for every , , otherwise . We can argue inductively, and show that is the identity over , for all . Note that condition (a) implies that is the identity over the remaining elements in , as required. For , we have that by condition (a). For , note that (a) implies that . By condition (b), . To see that , suppose by contradiction that , then condition (a) implies that , which violates (b). For the case , recall that is the above-defined enumeration of . Since is the identity over and by condition (a), we have that is the identity over . As and , conditions (a) and (b) imply that and , as required.
To conclude this example we note that the class of valued -structures where each is derived from by setting , and for all is an example of a finite-valued class of structures that has bounded treewidth modulo homomorphic equivalence but unbounded treewidth modulo equivalence.
Corollaries of the complexity classification
We can obtain the classification for CSPs of Dalmau et al.  and Grohe  as a special case of Theorem 19. Indeed, we can associate with a relational -structure a valued -structure such that (i) , (ii) and have the same universe , and (iii) if , then , otherwise , for every and . For a class relational structures, we define the class of valued structures . It is not hard to check that, when is of bounded arity, CSP(,) reduces in polynomial time to VCSP(,) and vice versa. Hence, a classification of CSP(,), for ’s of bounded arity, is equivalent to a classification of VCSP(,). Finally, note that has bounded treewidth modulo homomorphic equivalence if and only if has bounded treewidth modulo (valued) equivalence. This implies the known CSP classification from  and .
In his PhD thesis , Färnqvist also considered the complexity of VCSP(, ). However, he considered a different definition of the problem, that we denote by VCSP(, ). Formally, for a relational -structure , let be the valued -structure such that (i) , (ii) and have the same universe , and (iii) for every and , we have that and , for all . For a class of relational structures , VCSP(, ) is precisely the problem VCSP(, ), where . It was shown in  that for a class of relational structures of bounded arity, VCSP(, ) is tractable if and only if has bounded treewidth. This result follows directly from Theorem 19 as every valued structure in a class of the form is a (valued) core, and hence, bounded treewidth modulo equivalence boils down to bounded treewidth.
Intuitively, VCSP(, ) restricts VCSP only based on the (multiset of) tuples appearing in the structures from . In contrast, our definition of VCSP(, ) considers directly the structures in . This allows us for a more fine-grained analysis of structural restrictions, and in particular, provides us with new tractable classes beyond bounded treewidth. Indeed, as Example 22 illustrates, we can find simple tractable classes of valued structures with unbounded treewidth.
Finally, let us note that since Theorem 19 applies to all valued structures, it in particular covers the finite-valued VCSP, where all functions are restricted to take finite values in , and hence the tractability part of Theorem 19 directly applies to the finite-valued case. The hardness part also applies to the finite-valued case. Indeed, the right-hand side structure constructed in the reduction of Proposition 24 is actually finite-valued. Therefore, Theorem 19 also gives a classification for finite-valued VCSPs. Moreover, Examples 22 and 23 demonstrate that already for finite-valued structures the tractability frontier is strictly between bounded treewidth and bounded treewidth modulo homomorphic equivalence.