1 Introduction

1.1 Background and motivation

In this paper we study a model that involves fairly partitioning a set of agents into disjoint coalitions of size three. In terms of the literature, this model could be described as either a hedonic game with fixed size coalitions, of size three, or a model of Three Dimensional Roommates (3DR). We assume that agents’ preferences are additively separable, or equivalently that each agent assigns a numerical valuation to every other agent. This assumption means this model is equivalent to an Additively Separable Hedonic Game (ASHG), which is a type of cooperative game [1, 2]. The “hedonic” aspect means that “every agent only cares about which agents are in its coalition, but does not care how agents in other coalitions are grouped together” [3, 4]. This is a natural assumption to make in the study of multi-agent systems [5].

In this model, we assume that agents’ utility in some partition is the sum of its valuations of the other agents in its coalition, and agents always prefer coalitions with greater utility. In some partition, we say that some agent \(\alpha _i\) has envy for another agent \(\alpha _j\) if \(\alpha _i\) prefers to swap places with \(\alpha _j\). If no such \(\alpha _i\) exists then we say that the partition is envy-free. Part of our contribution regarding this model is on the existence of, and complexity of finding, partitions that are envy-free.

We also consider two other types of envy, which are called weakly justified envy, and justified envy. Informally, if agent \(\alpha _i\) has envy for agent \(\alpha _j\) then it is justified if the other agents in the coalition of \(\alpha _j\) strictly prefer \(\alpha _i\) to \(\alpha _j\). It is weakly justified if the other agents in the coalition of \(\alpha _j\) either prefer \(\alpha _i\) to \(\alpha _j\) or are indifferent.

A strong motivation exists for studying notions of envy in a model in which coalitions have a fixed size. Primarily, in a model in which coalitions have arbitrary size it can be trivial to construct partitions that are envy-free, for example by assigning all the agents to a single coalition [6, 7]. In addition, most of the previous work involving coalitions of fixed size involves finding partitions that are stable, meaning there exists no coalition S in which each agent in S prefers S to their assigned coalition in the partition [8,9,10,11,12].

More generally, much less is known about models in which coalitions have a fixed size compared to other models, such as hedonic games. It has also been argued in the literature that the assumption made in hedonic games that coalitions may have any size is unrealistic in practice [13]. In a real-life application there are likely to be constraints on the number or size of coalitions. For example, in a setting in which people are assigned to teams for specific projects it could be that the size of each team is limited [14], or must be exactly some fixed size. Team chess tournaments can involve teams of a fixed size, which at some amateur events [15, 16] is exactly three. Moreover, in the International Chess Federation rules for team chess [17], team chess matches are played between two individuals, points awarded to a team for each match won or drawn, and the tournament won by the team with the most points. We could imagine that players’ preferences over teams are therefore additively separable.

A strong theoretical motivation also exists for considering coalitions of size three in particular. Similar models involving coalitions of size two, like the Stable Roommates [18] problem, are comparatively well studied and well understood. In many such models, a stable or envy-free partition is bound to exist, or the problem of deciding whether such a partition exists can be solved in polynomial time. For example, deciding whether an envy-free partition exists can be trivial because such a partition must assign each agent to one of its “most preferred” partners [19]. In other words, it must be a perfect partition [20].

In comparison, models in which coalitions have size three (or more) do not seem so straightforward. For example, many of the computational problems associated with stability are \(\textsf {NP}\)-hard even when coalitions must have size three [10,11,12, 21]. It seems very likely that such hardness results can be generalised to larger coalition sizes. For this reason, we consider our contribution to be a first step towards exploring the frontier between polynomial-time solvability and \(\textsf {NP}\)-hardness for fixed-size coalitions.

The fact that many of the related computational problems associated with stability are \(\textsf {NP}\)-hard [10,11,12, 21] also motivates the study of justified envy-freeness, which is a strictly weaker concept than stability (see Sect. 1.2).

1.2 Preliminaries

An ASHG comprises a set of agents N with additively separable preferences over coalitions, which we define as follows. Each agent \(\alpha _i\) has an integer valuation function \(v_{\alpha _i}: N \mapsto {\mathbb {Z}}\). For convenience, for each agent \(\alpha _i\) let \(v_{\alpha _i}(\alpha _i) = 0\). An ASHG is a pair (NV) where V is a collection of all agents’ valuation functions. In our model we assume that \(|N|=3n\) for some integer n where \(n \ge 1\). We also refer to coalitions of size three as triples. For some partition into triples \(\pi\) and any set of agents S, let \(\sigma (S, \pi )\) be the number of triples in \(\pi\) that each contains at least one agent in S.

For some agent \(\alpha _i\) and some triple S, let the utility of \(\alpha _i\) in the triple S be \(u_{\alpha _i}(S) = \sum _{\alpha _j \in S} v_{\alpha _i}(\alpha _j)\). For some set of agents R, let \(u_{R}(S)=\sum _{\alpha _j \in R} u_{\alpha _j}(S)\). For some partition into triples \(\pi\) and some agent \(\alpha _i\) let \(\pi (\alpha _i)\) be the coalition in \(\pi\) that contains \(\alpha _i\). Since preferences are hedonic, given a partition \(\pi\) let \(u_{\alpha _i}(\pi )\) be short for \(u_{\alpha _i}(\pi (\alpha _i))\).

Fig. 1
figure 1

An example ASHG (NV) containing six agents and a partition into triples \(\pi\), marked by the dashed enclosure. The weighted arcs depict the agents’ valuations. Unless otherwise specified, \(v_{\alpha _i}(\alpha _j) = 0\) for any \(\alpha _i\) and \(\alpha _j\) in N

In some partition into triples \(\pi\), we say that an agent \(\alpha _i\) has envy for another agent \(\alpha _j\) if \(u_{\alpha _i}(\pi (\alpha _j) {\setminus } \{ \alpha _j \}) > u_{\alpha _i}(\pi )\). In other words, \(\alpha _i\) would gain a utility higher than its utility in \(\pi\) if it were to swap places with \(\alpha _j\). We say that a partition in which no agent has envy for another agent is envy-free.

Suppose \(\alpha _i\) has envy for \(\alpha _j\) in some partition into triples \(\pi\). We say that this envy is justified (j-envy) if \(v_{\alpha _k}(\alpha _i) > v_{\alpha _k}(\alpha _j)\) for each \(\alpha _k\) in \(\pi (\alpha _j) \setminus \{ \alpha _j \}\). Informally, the other agents in the triple of the envied agent \(\alpha _j\) all prefer the envying agent \(\alpha _i\) to \(\alpha _j\).

Similarly, we say that envy is weakly justified (wj-envy) if \(v_{\alpha _k}(\alpha _i) \ge v_{\alpha _k}(\alpha _j)\) for each \(\alpha _k\) in \(\pi (\alpha _j) {\setminus } \{ \alpha _j \}\). Now each other agent in the triple of the envied agent \(\alpha _j\) would be no worse off by swapping \(\alpha _j\) for the envying agent \(\alpha _i\).

A partition in which no agent has j-envy for another agent is justified envy-free (j-envy-free). Similarly, a partition in which no agent has wj-envy for another agent is weakly justified envy-free (wj-envy-free). By definition, the condition of envy-freeness is stronger than that of weakly justified envy-freeness, which is in turn stronger than justified envy-freeness.

To illustrate these solution concepts, we present an example instance in Fig. 1. In this example, we can see that \(\alpha _1\) has envy for \(\alpha _4\), since \(u_{\alpha _1}(\pi ) = 4 + 1 < 3 + 3 = u_{\alpha _1}(\pi (\alpha _4) {\setminus } \{ \alpha _4 \})\). This envy is weakly justified since \(v_{\alpha _5}(\alpha _4) = 2 \le 2 = v_{\alpha _5}(\alpha _1)\) and \(v_{\alpha _6}(\alpha _4) = 2 \le 3 = v_{\alpha _6}(\alpha _1)\). Since \(v_{\alpha _5}(\alpha _4) = v_{\alpha _5}(\alpha _1) = 2\), this envy is not justified.

We also define the solution concept of stability in our model. Given an ASHG (NV) and a partition into triples \(\pi\), we say that a triple \(\{\alpha _i, \alpha _j, \alpha _k \}\) blocks \(\pi\) if \(u_{\alpha _i}(\{\alpha _j, \alpha _k \})> u_{\alpha _i}(\pi ), u_{\alpha _j}(\{\alpha _i, \alpha _k \}) > u_{\alpha _j}(\pi )\), and \(u_{\alpha _k}(\{\alpha _i, \alpha _j \}) > u_{\alpha _k}(\pi )\). We say that a partition \(\pi\) is stable if no triple of any three agents blocks \(\pi\). In the example instance in Fig. 1, \(\{ \alpha _1, \alpha _5, \alpha _6 \}\) blocks \(\pi\).

In this paper we consider three types of restriction on the agents’ valuations. If \(v_{\alpha _i}(\alpha _j)=v_{\alpha _j}(\alpha _i)\) for any pair of agents \(\alpha _i, \alpha _j\) then preferences are symmetric. If \(v_{\alpha _i}(\alpha _j)\in \{0, 1\}\) for any pair of agents \(\alpha _i, \alpha _j\) then preferences are binary (also called simple [22, 23]). Similarly, if \(v_{\alpha _i}(\alpha _j)\in \{0, 1, 2\}\) for any such \(\alpha _i, \alpha _j\) then preferences are ternary.

If preferences are binary and symmetric then they can be represented as an undirected graph, which we call the underlying graph. Formally, we represent the underlying graph as a pair (NE) such that \(\{ \alpha _i, \alpha _j \} \in E\) if and only if \(v_{\alpha _i}(\alpha _j) = 1\). The maximum degree of such an ASHG is then the maximum degree of its underlying graph. We use standard graph-theoretic terminology when referring to the underlying graph. For example, in the context of some underlying graph (NE), for any agent \(\alpha _i\) in N, let \({\mathcal {N}}(\alpha _i)\) be the open neighbourhood of \(\alpha _i\) in (NE), meaning \(\alpha _j \in {\mathcal {N}}(\alpha _i)\) if and only if \(\{ \alpha _i, \alpha _j \} \in E\) and \(\alpha _j \ne \alpha _i\). Let \(\deg (\alpha _i) = |{\mathcal {N}}(\alpha _i)|\) be the degree of \(\alpha _i\) in (NE). We say that an agent is isolated if it has degree 0. A k-path or k-cycle is a path or cycle of k agents. We shall label the consecutive agents in a path or cycle as a list. For example, if some component P is a path or a cycle then the consecutive agents in P will be labelled \(( p_1, p_2, \dots , p_{|P|} )\), where \(\{ p_i, p_{i+1} \} \in E\) for each i where \(1\le i < |P|\).

1.3 Our contribution

In this paper we study the existence of envy-free, weakly justified envy-free, and justified envy-free partitions into triples and the complexity of the associated search problems. Specifically, we explore what happens when the agents’ valuations are somehow restricted. We identify various dichotomies between polynomial-time solvability and \(\textsf {NP}\)-hardness, shown in Table 1. In the table, the symbols “\(\checkmark\)” and “✗” are short for “must exist” and “may not exist” respectively. The complexity class shown refers to the problem of finding a partition that satisfies the relevant solution concept in an instance in which the valuations are restricted as shown.

1.3.1 Structure of the paper

In Sect. 1 we provide some background, formally define the necessary concepts and terminology, and discuss some related previous work.

In Sect. 2 we show that an ASHG may not contain an envy-free partition into triples, even if the preferences are binary and symmetric and the maximum degree of the underlying graph is 2. We describe a polynomial-time algorithm for this case that either constructs an envy-free partition into triples or reports that no such partition exists (Theorem 2.2). We then contrast this result by showing that the corresponding existence problem is \(\textsf {NP}\)-complete even when the maximum degree of the underlying graph is 3 (Theorem 2.9).

Table 1 Our existence and complexity results

In Sect. 3 we identify a similar dichotomy for weakly justified envy-freeness. We first show that a weakly justified envy-free partition into triples may not exist, even when preferences are binary and symmetric and the maximum degree of the ASHG is 2. We describe a slightly more complex polynomial-time algorithm for this case that either constructs a weakly justified envy-free partition into triples or reports that no such partition exists (Theorem 3.24). As for envy-freeness, we show that the corresponding existence problem is also \(\textsf {NP}\)-complete even when the maximum degree of the underlying graph is 3 (Theorem 3.31). We remark that the set of ASHGs with maximum degree 2 that do not contain a weakly justified envy-free partition into triples is a strict subset of the set of ASHGs with maximum degree 2 that do not contain an envy-free partition into triples.

In Sect. 4 we consider justified envy-freeness. We first observe that if a partition into triples is stable then it is also justified envy-free. We then show that if preferences are binary but not necessarily symmetric, a justified envy-free partition into triples must exist and can be found in polynomial time, making use of a potential function [24] (Theorem 4.3). We complement this result with two hardness results. The first is that a given ASHG may not contain a justified envy-free partition into triples even when preferences are ternary but not necessarily symmetric, and the associated existence problem is \(\textsf {NP}\)-complete (Theorem 4.12). The second is that a given ASHG may not contain a justified envy-free partition into triples even when preferences are symmetric but not necessarily binary, and the associated existence problem is \(\textsf {NP}\)-complete (Theorem 4.16). We also remark that it seems unclear how to design an ASHG with symmetric preferences in which there is no justified envy-free partition into triples. The authors used an integer programming model in combination with a guided computer search. We discuss this technique further in Sect. 4.3.

In Sect. 5 we conclude the paper and consider some possible directions for future work.

1.4 Related work

We discuss previous work on:

  • Envy-freeness and coalitions of restricted size, in Sect. 1.4.1

  • Envy-freeness and coalitions of unrestricted size, including work on hedonic games, in Sect. 1.4.2

  • Coalitions of fixed size, but not in relation to envy-freeness, including on three- and multi-dimensional roommates, in Sect. 1.4.3

For other models of coalition formation, coalitions of unrestricted size, hedonic games, and solution concepts not involving envy, a wealth of literature exists [20, 25,26,27].

1.4.1 Envy-freeness and restricted coalition size

To our knowledge, there are four previous papers involving envy-freeness and coalitions of restricted size.

The first paper is by Coutance et al. [19] who in 2023 considered variants of envy-freeness in a model in which coalitions must have size two and agents have ordinal preferences over possible pairs. They noted that since it is trivial to decide whether an envy-free partition exists. They therefore studied rank-envy-freeness and some of its variants.

The second paper is by Li et al. [28] who, also in 2023, considered a strictly more general model than ours. Rather than fixing the size of each coalition, a partition of the n agents must be balanced, meaning there is a fixed number of coalitions \(k\le n\) such that \(\lfloor n/k \rfloor \le |S| \le \lceil n/k \rceil\) for any coalition S in a feasible partition. They studied a generalisation of envy-freeness, termed envy-free up to r (EF-r), in which the utility gained by any envious agent in a feasible partition may be up to r, for some fixed \(r \ge 0\). Our definition of envy-freeness is thus EF-0. Interestingly, the authors applied results from discrepancy theory to show that an approximate envy-free partition with a particular fixed asymptotic bound must exist, and can be found in polynomial time. They also considered restricted types of instances, such those in which the underlying structure is a tree. They showed that in such an instance, an EF-1 partition must exist and can be found in polynomial time. A coalition partition in which every coalition has size three is by definition balanced, so some of the polynomial-time solvability results on approximate envy-free partitions [28, Theorems 9 and 10] also apply to our model.

The third paper, also published in 2023, is by Gan et al. [29]. The authors defined a general model in which a set of agents is assigned to a set of resources such that a single resource can be shared by one or more agents. In their model, the authors characterised the relationship between proportional and envy-free assignments. They also defined Pareto Envy-Freeness (PEF), which is a relaxation of envy-freeness as defined in that setting. The authors also study a restricted case of the general model in which agents are assigned to resources with the same capacity (“dorms”). Each agent has binary and symmetric preferences over all other agents, as dorm-mates, and additively separable preferences over possible dorms. The main result is that if all dorms have capacity 2 then a PEF assignment must exist and can be found in polynomial time. It is also shown that if dorms have capacity three then a PEF assignment does not necessarily exist. The model we study in this paper can be seen as a type of special case of the latter model in which the agents are indifferent between possible dorms.

The fourth paper, published in 2020, is by Boehmer and Elkind [30]. The authors considered a model in which a set of agents is to be partitioned into sets of equal size. Notably, the desired coalition size is fixed but supplied as part of the problem input. In their model, each agent’s preference between possible coalitions is highly constrained. Each agent belongs to one of a number of types and compares two possible coalitions by considering only the proportion of agents in each coalition of each type. The authors presented results for a number of solution concepts, including envy-freeness as we define it here. In particular, they showed that an envy-free partition does not necessarily exist and the associated decision problem is \(\textsf {NP}\)-complete, even when agents’ preferences are highly restricted. They also showed that the problem of deciding whether an envy-free partition exists is fixed-parameter tractable in terms of the coalition size.

1.4.2 Envy-freeness and unrestricted coalition size

In a comprehensive study on ASHGs published in 2013, Aziz et al. [20] defined envy-freeness as a solution concept in ASHGs. They noted that the singleton partition (in which each agent belongs to a coalition of size one) is trivially envy-free and therefore considered the existence of partitions that simultaneously satisfy envy-freeness and some other solution concept. Of course, the existence of such a trivial envy-free partition forms a strong motivation for somehow bounding the size of acceptable coalitions.

Stability, envy-freeness, and justified envy-freeness were also considered by Ueda [7] in 2018, in a hedonic game in which each agent has ordinal preferences over all possible coalitions. He too observed that both the singleton partition and the grand partition (in which there is one coalition containing all the agents) are trivially envy-free. He also observed that there exist instances in which no non-trivial partition is envy-free, and additional instances in which no non-trivial partition is justified envy-free. Finally, he showed that any stable partition [3] is also justified envy-free.

Barrot and Yokoo [6] noted Ueda’s observations in 2019 and continued exploring the existence of partitions that satisfy a combination of solution concepts, including envy-freeness, weakly justified envy-freeness, and justified envy-freeness. As well as some non-existence results on ASHGs, they also considered more general systems of preference representation. Notably, they proved results on the existence of satisfactory coalition partitions in a setting in which preferences are either top responsive and bottom responsive (or bottom refuse), two restrictions previously well-established in the hedonic games literature.

1.4.3 Other solution concepts and restricted coalition size

The Stable Roommates problem, which can be viewed as a type of hedonic game, involves assigning a set of agents into pairs such that the resulting partition is stable [18]. It is a classical problem of matching under preferences and has been studied extensively. Its three-dimensional case has also received some attention, and a few specific models of Three-Dimensional Stable Roommates have been studied in the literature [8,9,10,11,12].

Sless et al. [13] proposed a model in 2018 that can be viewed as a type of ASHG with symmetric preferences. Arguing that there is a practical motivation for coalitions of restricted size, they focused on the existence of coalition partitions that contain exactly k coalitions, for some fixed k where \(k \ge 1\). The authors presented both theoretical and empirical results relating to this model. They showed that the problem of finding a partition with maximum utilitarian welfare can be solved in polynomial time in the restricted case in which k is fixed and there are, in a precise sense, relatively few negative edges. Otherwise, this construction problem is \(\textsf {NP}\)-hard. They also presented other polynomial-time solvability results for a problem in which a central organiser can add some edges to the instance.

In 2019, Cseh et al. [31] considered Pareto optimal partitions in a model that is similar to the model of Gan et al. [29] discussed previously. In the model of Cseh et al., there is a set of rooms with integer sizes and any coalition must be allocated to exactly one room where the size of the room is exactly the size of the coalition. Cseh et al. studied two specific variants of this model, involving so-called \({\mathscr {B}}\)- and \({\mathscr {W}}\)-preferences. They showed that if agents have \({\mathscr {B}}\)-preferences and strict preference lists then a polynomial-time algorithm based on serial dictatorship can be used to construct a Pareto optimal partition in polynomial time. They also showed that in various other cases a Pareto optimal partition may not exist and that the associated existence problems are either \(\textsf {NP}\)-hard or \(\textsf {NP}\)-complete.

In 2022, Bilò et al. [22] studied ASHGs in which the coalition size is fixed and agents have binary and symmetric preferences. They considered swap stability and two related solution concepts called strict swap stability and swap stability under transferable utilities. If a partition \(\pi\) is strictly swap stable then no agents \(\alpha _i\) and \(\alpha _j\) exist such that \(\alpha _i\) could swap places with \(\alpha _j\) to produce a partition \(\pi ^{\prime }\) in which \(u_{\alpha _i}(\pi ^{\prime }) > u_{\alpha _i}(\pi )\) and \(u_{\alpha _j}(\pi ^{\prime }) > u_{\alpha _j}(\pi )\). If a partition \(\pi\) is swap stable then no two agents \(\alpha _i\) and \(\alpha _j\) exist such that \(\alpha _i\) could swap places with \(\alpha _j\) to produce a partition \(\pi ^{\prime }\) in which \(u_{\alpha _i}(\pi ^{\prime }) > u_{\alpha _i}(\pi )\) and \(u_{\alpha _j}(\pi ^{\prime }) \ge u_{\alpha _j}(\pi )\). If a partition \(\pi\) is swap stable under transferable utilities then no two agents \(\alpha _i\) and \(\alpha _j\) exist such that \(\alpha _i\) could swap places with \(\alpha _j\) to produce a partition \(\pi ^{\prime }\) in which \(u_{\alpha _i}(\pi ^{\prime }) + u_{\alpha _j}(\pi ^{\prime }) > u_{\alpha _i}(\pi ) + u_{\alpha _j}(\pi )\). Bilò et al. noted that a related solution concept had been previously studied as “exchange stability” [32]. It is straightforward to show that envy-freeness implies swap stability under transferable utilities. In fact, we illustrate in Fig. 2 the hierarchical relationships between various solution concepts in ASHGs, including those studied by Bilò et al. Note that a perfect partition is one in which each agent gains its maximum possible utility [20].

Fig. 2
figure 2

Part of the known hierarchy of solution concepts in hedonic games [3, 6, 22]. In the diagram, an arrow points from one concept to another if any partition that satisfies the former must also satisfy the latter. This figure is adapted from the Handbook of Computational Social Choice [3, Figure 15.1]

2 Envy-freeness

In this section we consider envy-freeness in ASHGs with binary and symmetric preferences.

First, in Sect. 2.1, we consider ASHGs with maximum degree 2. We show that in polynomial time we can either construct an envy-free partition into triples or report that no such partition exists (Theorem 2.2).

Next, in Sect. 2.2, we consider ASHGs with maximum degree 3. We show that such an ASHG may not contain an envy-free partition into triples and the associated existence problem is \(\textsf {NP}\)-complete.

2.1 Binary and symmetric preferences with maximum degree 2

Our first result is a necessary and sufficient condition for the existence of an envy-free partition into triples in an ASHG with binary and symmetric preferences and maximum degree 2. In other words, an ASHG in which every component of the underlying graph is either a path or a cycle.

Lemma 2.1

Consider an ASHG with binary and symmetric preferences and maximum degree 2. Let P be the set of isolated agents, \({\mathcal {Q}}\) be the set of components of \(3{k_1} - 2\) agents for any integer \({k_1} > 1\), and \({\mathcal {R}}\) be the set of components of \(3{k_2} - 1\) agents for any integer \({k_2} \ge 1\). An envy-free partition into triples exists if and only if \(2|{\mathcal {Q}}| + |{\mathcal {R}}| \le |P|\).

Proof

Suppose (NE) is the underlying graph of an arbitrary ASHG with binary and symmetric preferences and maximum degree 2. Let \(P=\{ p_1, p_2, \dots , p_{|P|} \}\) be the set of isolated agents, \({\mathcal {Q}} = \{ Q_1, Q_2, \dots , Q_{|{\mathcal {Q}}|} \}\) be the set of components of \(3{k_1} - 2\) agents for any integer \({k_1} > 1\), and \({\mathcal {R}}=\{ R_1, R_2,\dots , R_{|{\mathcal {R}}|} \}\) be the set of components of \(3{k_2} - 1\) agents for any integer \({k_2} \ge 1\). Let \({\mathcal {S}}=\{S_1,S_2,\dots ,S_{|{\mathcal {S}}|}\}\) be the set of components of \(3{k_3}\) agents for any integer \({k_3} \ge 1\).

To show the first direction, suppose \(2|{\mathcal {Q}}| + |{\mathcal {R}}| \le |P|\). We shall construct a partition into triples \(\pi\) and demonstrate that it is envy-free. First, note that if any agent has utility 1 or more then that agent is not envious, since the maximum degree of (NE) is 2.

Construct \(\pi\) as follows. First, consider each component S in \({\mathcal {S}}\), with consecutive agents labelled \(( s_1, s_2, \dots , s_{3{k_3}} )\). For each i where \(1\le i\le {k_3}\), add \(\{ s_{3i-2}, s_{3i-1}, s_{3i} \}\) to \(\pi\). It follows that each agent in S has utility at least 1 and is therefore not envious.

Now consider each component R in \({\mathcal {R}}\), with consecutive agents labelled \(( r_1, r_2, \dots , r_{3{k_2}-1} )\). For each i where \(1\le i \le {k_2}-1\), add \(\{ r_{3i-2}, r_{3i-1}, r_{3i} \}\) to \(\pi\). Next, add \(\{ r_{3{k_2}-2}, r_{3{k_2}-1}, p_{2|{\mathcal {Q}}|+i} \}\) to \(\pi\) (recalling that \(|P| \ge 2|{\mathcal {Q}}| + |{\mathcal {R}}|\)). It follows that each agent in R has utility at least 1 and is therefore not envious.

Now consider each component Q in \({\mathcal {Q}}\), with consecutive agents labelled \(( q_1, q_2, \dots , q_{3{k_1}-2} )\). For each i where \(1\le i \le {k_1}-2\), add \(\{ q_{3i-2}, q_{3i-1}, q_{3i} \}\) to \(\pi\). Next, add to \(\pi\) the triples \(\{ q_{3{k_1}-5}, q_{3{k_1}-4}, p_{i} \}\) and \(\{ q_{3{k_1}-3}, q_{3{k_1}-2}, p_{2i} \}\). It follows that each agent in Q has utility at least 1 and is therefore not envious.

Finally, arbitrarily add the remaining agents in P to triples in \(\pi\). Since these agents are isolated they are also not envious.

To show the second direction, suppose for a contradiction that the ASHG represented by (NE) has an envy-free partition into triples \(\pi\) and \(2|{\mathcal {Q}}| + |{\mathcal {R}}| > |P|\). Since the degree of any agent in any component in \({\mathcal {Q}}\) is at least 1, it must be that the utility of each agent in any component in \({\mathcal {Q}}\) is at least 1, for otherwise such an agent is envious. Similarly, the utility of each agent in any component in \({\mathcal {R}}\) must also be at least 1. It follows that any agent with utility 0 belongs to P.

Now consider some component Q in \({\mathcal {Q}}\). By definition, Q has \(3{k_1} - 2\) agents for some integer \(k_1\) where \({k_1} > 1\). The only possibility is that there exist two triples in \(\pi\) that each contains exactly two agents in Q and some agent with utility 0. Similarly, for any R in \({\mathcal {R}}\) there must exist at least one triple in \(\pi\) that contains exactly two agents in R and some agent with utility 0. It follows that there are in total at least \(2|{\mathcal {Q}}| + |{\mathcal {R}}|\) agents with utility 0. The only possibility is that there are at least \(2|{\mathcal {Q}}| + |{\mathcal {R}}|\) such agents in P, which is a contradiction.\(\quad \square\)

Lemma 2.1 shows a necessary and sufficient condition for the existence of an envy-free partition into triples. In fact, the constructive proof of this lemma can be adapted to show that there exists an O(|N|)-time algorithm that either constructs an envy-free partition into triples or reports that no such partition exists. We state this as Theorem 2.2 and defer the formal proof to Appendix A.

Theorem 2.2

Consider an ASHG with binary and symmetric preferences and maximum degree 2. There exists an O(|N|)-time algorithm that either constructs an envy-free partition into triples or reports that no such partition exists.

2.2 Binary and symmetric preferences with maximum degree 3

We now consider ASHGs with binary and symmetric preferences and maximum degree 3. We show that deciding if a given ASHG contains an envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are binary and symmetric and the maximum degree is 3.

We present a polynomial-time reduction from a variant of Exact Satisfiability (XSAT) [33]. An instance of XSAT is a boolean formula in conjunctive normal form (CNF). We represent such a formula as the set of its clauses \(C=\{ c_1, c_2, \dots , c_{m} \}\). We represent each clause \(c_r\) in C as a set of literals. Each literal is either an occurrence of a single variable or its negation. We write X(C) to mean the set of variables contained in the formula C. A truth assignment \(f: X(C) \mapsto \{\text {true}, \text {false}\}\) is an assignment of values to the set of variables. We say that an exact model is a truth assignment to the variables such that each clause contains exactly one true literal (and therefore exactly two false literals). Given a formula C, if an exact model exists then we say that C is exactly satisfiable.

Deciding if a given instance C of XSAT is exactly satisfiable is \(\textsf {NP}\)-complete, even in the restricted case in which each clause contains exactly three literals [34]. We call this restricted case 3-XSAT, but it is sometimes referred to as 1-in-3 SAT. A result of Porschen et al. [35, Lemma 5] shows that 3-XSAT remains \(\textsf {NP}\)-complete even in the restricted case in which each literal is positive and each variable occurs in exactly three clauses. We call this variant \(\text {X3SAT}_{+}^{\,=3}\) (Problem 2.3), but it is sometimes referred to as 1-in-3 Positive 3-Occurrence-SAT [8]. Note that in an instance C of \(\text {X3SAT}_{+}^{\,=3}\) it must be that \(|X(C)|=m\).

Problem 2.3

\(\text {X3SAT}_{+}^{\,=3}\)

      Input: a boolean formula C in conjunctive normal form, in which every

      literal is positive and each variable occurs in exactly three clauses

      Question: is C exactly satisfiable?

The reduction, illustrated in Fig. 3, is as follows. Suppose C is an arbitrary instance of \(\text {X3SAT}_{+}^{\,=3}\). We shall construct an ASHG represented by an underlying graph (NE).

For each variable \(x_i\) in X(C), there are three corresponding literals in three different clauses. For each such \(x_i\), arbitrarily label each of these literals as the first, second, and third occurrences of \(x_i\).

Fig. 3
figure 3

The reduction from \(\text {X3SAT}_{+}^{\,=3}\) to the problem of deciding if a given ASHG contains an envy-free partition into triples. A variable gadget \(W_i\) and clause gadget \(D_r\) are represented as undirected graphs

For each such \(x_i\), construct a set of three agents \(W_i = \{ w_i^1, w_i^2, w_i^3 \}\), which we refer to as the \(i^{th}\) variable gadget. Add edges \(\{ w_i^1, w_i^2 \}\), \(\{ w_i^2, w_i^3 \}\), and \(\{ w_i^3, w_i^1 \}\). Next, for each clause \(c_r\) in C construct a set of eight agents \(D_r = \{ d_r^1, d_r^2, \dots , d_r^8 \}\), which we refer to as the \(r^{th}\) clause gadget. Add edges \(\{ d_r^1, d_r^4 \}\), \(\{ d_r^2, d_r^5 \}\), \(\{ d_r^3, d_r^8 \}\), \(\{ d_r^4, d_r^6 \}\), \(\{ d_r^4, d_r^7 \}\), \(\{ d_r^5, d_r^6 \}\), \(\{ d_r^5, d_r^7 \}\), \(\{ d_r^8, d_r^6 \}\), and \(\{ d_r^8, d_r^7 \}\).

Now we shall connect the variable and clause gadgets. Consider each clause \(c_r = \{ x_i, x_j, x_k \}\). If \(c_r\) contains the first occurrence of \(x_i\) then add the edge \(\{ d_r^1, w_i^1 \}\). Similarly, if \(c_r\) contains the second occurrence of \(x_i\) then add the edge \(\{ d_r^1, w_i^2 \}\). Similarly, if \(c_r\) contains the third occurrence of \(x_i\) then add the edge \(\{ d_r^1, w_i^3 \}\).

In the same way, add an edge between \(d_r^2\) and an agent in \(W_j\) depending on the index of the occurrence of \(x_j\) in \(c_r\). Finally, add an edge between \(d_r^3\) and an agent in \(W_k\) depending on the index of the occurrence of \(x_k\) in \(c_r\). Let us now say that the clause gadget \(D_r\) is adjacent to the variable gadgets \(W_i\), \(W_j\), and \(W_k\), and vice-versa.

The construction of (NE) is now complete. Note that each agent in a variable gadget has degree 3, the agents \(d_r^4\), \(d_r^5\), \(d_r^6\), \(d_r^7\), and \(d_r^8\) for each \(1 \le r \le m\) have degree 3, and the agents \(d_r^1, d_r^2, d_r^3\) for each \(1 \le r \le m\) have degree 2. It follows that the maximum degree of (NE) is 3.

It is straightforward to show that this reduction can be performed in polynomial time. To prove that the reduction is correct we show that the ASHG represented by (NE) contains an envy-free partition into triples if and only if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable.

We first prove some ancillary lemmas. Recall that for any set of agents S, \(\sigma (S, \pi )\) is the number of triples in \(\pi\) that each contains at least one agent in S. Recall also that for any agent \(\alpha _i\) we write \({\mathcal {N}}(\alpha _i)\) to mean the open neighbourhood of \(\alpha _i\).

Lemma 2.4

Suppose \(\pi\) is a partition into triples in the ASHG represented by (NE). For any agent \(\alpha _i\), if \(u_{\alpha _i}(\pi )=1\) and \(\sigma ({\mathcal {N}}(\alpha _i), \pi )=\deg (\alpha _i)\) then \(\alpha _i\) is not envious in \(\pi\).

Proof

Suppose, to the contrary, that \(\alpha _i\) envies some agent \(\alpha _j\). Then \(u_{\alpha _i}(\pi (\alpha _j) {\setminus } \{ \alpha _j \})=2\). It must be that two agents in \({\mathcal {N}}(\alpha _i)\) belong to the same triple, namely \(\pi (\alpha _j)\). It follows that \(\sigma ({\mathcal {N}}(\alpha _i), \pi ) < \deg (\alpha _i)\), which is a contradiction. \(\hfill\square\)

Lemma 2.5

Suppose \(\pi\) is a partition into triples in the ASHG represented by (NE). For any agent \(\alpha _i\), if \(u_{\alpha _i}(\pi )=0\) then \(\alpha _i\) is envious in \(\pi\).

Proof

Suppose there exists some agent \(\alpha _i\) where \(u_{\alpha _i}(\pi )=0\). By the construction of (NE), it must be that \(\alpha _i\) has degree at least 1 so there exists some \(\alpha _j\) where \(\{ \alpha _i, \alpha _j \}\in E\). It follows that \(\alpha _i\) is envious of both agents in \(\pi (\alpha _j)\). \(\hfill\square\)

We now show that if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable then the ASHG represented by (NE) contains an envy-free partition into triples.

Lemma 2.6

If C is exactly satisfiable then the ASHG represented by (NE) contains an envy-free partition into triples.

Proof

Suppose f is an exact model of C. We shall construct a partition into triples \(\pi\) that is envy-free. For each variable \(x_i\) in X(C) where \(f(x_i)\) is false, add \(\{ w_i^1, w_i^2, w_i^3 \}\) to \(\pi\). Now consider each clause \(c_r = \{ x_i, x_j, x_k \}\) and the corresponding clause gadget \(D_r\), labelling ijk such that \(W_i\) contains an agent adjacent to \(d_r^1\), \(W_j\) contains an agent adjacent to \(d_r^2\), and \(W_k\) contains an agent adjacent to \(d_r^3\). There are three cases: \(f(x_i)\) is true while both \(f(x_j)\) and \(f(x_k)\) are false, \(f(x_j)\) is true while both \(f(x_i)\) and \(f(x_k)\) are false, and \(f(x_k)\) is true while both \(f(x_i)\) and \(f(x_j)\) are false. In the first case, suppose \(c_r\) contains the \(u^{th}\) occurrence of \(x_i\). Add to \(\pi\) the triples \(\{ w_i^u, d_r^1, d_r^4 \}\), \(\{ d_r^2, d_r^5, d_r^7 \}\), and \(\{ d_r^3, d_r^6, d_r^8 \}\). The constructions in the second and third cases are symmetric. In the second case, suppose \(c_r\) contains the \(u^{th}\) occurrence of \(x_j\). Add to \(\pi\) the triples \(\{ w_j^u, d_r^2, d_r^5 \}\), \(\{ d_r^1, d_r^4, d_r^6 \}\), and \(\{ d_r^3, d_r^7, d_r^8 \}\). In the third case, suppose \(c_r\) contains the \(u^{th}\) occurrence of \(x_k\). Add to \(\pi\) the triples \(\{ w_k^u, d_r^3, d_r^8 \}\), \(\{ d_r^1, d_r^4, d_r^6 \}\), and \(\{ d_r^2, d_r^5, d_r^7 \}\).

The construction of \(\pi\) is now complete. Note that for any variable gadget \(W_i\), either \(\sigma (W_i, \pi ) = 1\) or \(\sigma (W_i, \pi ) = 3\). For each clause gadget \(D_r\), there exist two triples in \(\pi\) that each contains three agents in \(D_r\) and one triple in \(\pi\) that contains two agents in \(D_r\) as well as an agent in some variable gadget. There are therefore three kinds of triple in \(\pi\): a triple that contains three agents belonging to the same variable gadget; a triple that contains one agent in some variable gadget as well as two agents in some clause gadget; and a triple that contains three agents in the same clause gadget. We will show that no triple of any kind contains an envious agent.

First, consider some triple t in \(\pi\) of the first kind, where \(t = W_i\) for some variable gadget \(W_i\). Since each agent in t has utility 2, no agent in t is envious.

Second, consider some triple t in \(\pi\) of the second kind, which contains some agent \(w_i^a\) in some variable gadget \(W_i\) and two agents in some clause gadget \(D_r\). By the construction of \(\pi\), t comprises either \(\{ w_i^u, d_r^1, d_r^4 \}\), \(\{ w_i^a, d_r^2, d_r^5 \}\), or \(\{ w_i^a, d_r^3, d_r^8 \}\). Suppose t comprises \(\{ w_i^a, d_r^1, d_r^4 \}\). Since \(u_{d_r^1}(\pi )=2\) it follows that \(d_r^1\) is not envious. Since \(\sigma (W_i, \pi ) = 3\) and \(u_{w_i^a}(\pi )\ge 1\) it follows by Lemma 2.4 that \(w_i^a\) is also not envious. Similarly, since \(\sigma ({\mathcal {N}}(d_r^4), \pi )=3\) it follows by Lemma 2.4 that \(d_r^4\) is also not envious. The proof in the other cases, in which t comprises either \(\{ w_i^a, d_r^2, d_r^5 \}\) or \(\{ w_i^a, d_r^3, d_r^8 \}\), is symmetric.

Third, consider some triple t in \(\pi\) of the third kind, where \(t\subset D_r\) for some clause gadget \(D_r\). By the construction of \(\pi\), t comprises either \(\{ d_r^1, d_r^4, d_r^6 \}\), \(\{ d_r^2, d_r^5, d_r^7 \}\), \(\{ d_r^3, d_r^6, d_r^8 \}\), or \(\{ d_r^3, d_r^7, d_r^8 \}\). Suppose t comprises \(\{ d_r^1, d_r^4, d_r^6 \}\). Since \(\sigma ({\mathcal {N}}(d_r^1), \pi )=2\) and \(u_{d_r^1}(\pi )=1\) it follows by Lemma 2.4 that \(d_r^1\) is not envious. Similarly, since \(\sigma ({\mathcal {N}}(d_r^6), \pi )=3\) and \(u_{d_r^6}(\pi )=1\) it follows by Lemma 2.4 that \(d_r^6\) is not envious. Since \(u_{d_r^4}(\pi )=2\) it follows that \(d_r^4\) is not envious. The proofs for the other three cases, in which t comprises either \(\{ d_r^2, d_r^5, d_r^7 \}\), \(\{ d_r^3, d_r^6, d_r^8 \}\), or \(\{ d_r^3, d_r^7, d_r^8 \}\), are symmetric. \(\hfill\square\)

We now show that if the ASHG represented by (NE) contains an envy-free partition into triples then the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable. For any partition into triples \(\pi\) and any variable gadget \(W_i\), if \(\sigma (W_i, \pi ) = 3\) then let us say that \(W_i\) is open. If \(\sigma (W_i, \pi ) = 1\) then let us say that \(W_i\) is closed.

Lemma 2.7

If the ASHG represented by (NE) contains an envy-free partition into triples \(\pi\) then any variable gadget is either open or closed.

Proof

Suppose \(\pi\) is an envy-free partition into triples. For each variable gadget \(W_i\), since \(|W_i| = 3\) by definition \(1 \le \sigma (W_i, \pi ) \le 3\). Suppose for a contradiction that there exists some variable gadget \(W_i\) that is neither open nor closed, meaning \(\sigma (W_i, \pi ) = 2\). There must exist some triple \(\{ w_i^a, w_i^b, \alpha _j \}\) in \(\pi\) where \(w_i^a, w_i^b \in W_i\) and \(\alpha _j \notin W_i\). Label the remaining agent in \(W_i\) as \(w_i^c\). By the construction of \(W_i\), it must be that \(u_{w_i^c}(\pi )\le 1\). It follows that \(w_i^c\) envies \(\alpha _j\) since \(u_{w_i^c}(\pi (\alpha _j) \setminus \{ \alpha _j \}) = 2\). \(\hfill\square\)

Lemma 2.8

If the ASHG represented by (NE) contains an envy-free partition into triples then C is exactly satisfiable.

Proof

Suppose \(\pi\) is an envy-free partition into triples. By Lemma 2.7 any variable gadget is either open or closed. Construct a truth assignment f in C by setting \(f(x_i)\) to be true if \(W_i\) has an open configuration in \(\pi\) and false otherwise. Each variable \(x_i\) corresponds to exactly one variable gadget so it follows that f is a valid truth assignment. By the construction of (NE), each clause \(c_r\) corresponds to exactly one clause gadget \(D_r\). Recall that each clause gadget is adjacent to three variable gadgets, which correspond to the three variables in that clause. To show that f is an exact model of C, it is now sufficient to show that each clause gadget \(D_r\) is adjacent to exactly one open variable gadget.

Consider an arbitrary clause gadget \(D_r\) and the corresponding clause \(c_r=\{ x_i, x_j, x_k \}\), labelling ijk such that \(d_r^1\) is adjacent to some agent in \(W_i\), \(d_r^2\) is adjacent to some agent in \(W_j\) and \(d_r^3\) is adjacent to some agent in \(W_k\).

First suppose for a contradiction that \(D_r\) is adjacent to 0 open variable gadgets. It follows that \(W_i \in \pi\), \(W_j \in \pi\), and \(W_k \in \pi\). By Lemma 2.5, it must be that each of the five agents in \(D_r\) has utility 1 or more. It follows that any triple that contains at least one agent in \(D_r\) must either exactly two agents in \(D_r\) or exactly three agents in \(D_r\). Since there are five agents in \(D_r\), the only possibility is that there exists some triple \(\{ d_r^a, d_r^b, \alpha _m \}\) where \(\alpha _m \notin D_r\). It follows that \(u_{\alpha _m}(\pi ) = 0\), which contradicts Lemma 2.5.

Now suppose for a contradiction that either \(D_r\) is adjacent to two or more open variable gadgets. Without loss of generality, assume that \(W_j\) and \(W_k\) are open.

Suppose \(c_r\) contains the \(a^{th}\) occurrence of \(x_i\) and the \(b^{th}\) occurrence of \(x_j\). Consider \(\pi (w_i^a)\). By Lemma 2.5, no agent has utility 0 in \(\pi\), so \(\pi (w_i^a)\) comprises either \(\{ w_i^a, d_r^1, d_r^4 \}\), \(\{ w_i^a, d_r^2, d_r^5 \}\), or \(\{ w_i^a, d_r^3, d_r^8 \}\). Similarly, \(\pi (w_i^b)\) comprises either \(\{ w_i^b, d_r^1, d_r^4 \}\), \(\{ w_i^b, d_r^2, d_r^5 \}\), or \(\{ w_i^b, d_r^3, d_r^8 \}\). By the symmetry of the clause gadget, assume without loss of generality that \(\pi (w_i^a) = \{ w_i^a, d_r^1, d_r^4 \}\) and \(\pi (w_i^b) = \{ w_i^b, d_r^2, d_r^5 \}\). Now consider \(d_r^6\), \(d_r^7\), and \(d_r^8\). Since no agent has utility 0, the only possibility is that \(\{ d_r^6, d_r^7, d_r^8 \}\) belongs to \(\pi\). It then follows that \(d_r^4\) envies \(d_r^8\), since \(u_{d_r^4}(\pi )=1 < 2 = u_{d_r^4}(\{ d_r^6, d_r^7 \})\), which is a contradiction. \(\hfill\square\)

We have now shown that the ASHG represented by (NE) contains an envy-free partition into triples if and only if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable. This shows that the reduction is correct.

Theorem 2.9

Deciding if a given ASHG contains an envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are binary and symmetric and the ASHG has maximum degree 3.

Proof

It is straightforward to show that this decision problem belongs to \(\textsf {NP}\), since for any two agents \(\alpha _i, \alpha _j\) we can test if \(\alpha _i\) envies \(\alpha _j\) in constant time.

We have presented a polynomial-time reduction from \(\text {X3SAT}_{+}^{\,=3}\), which is \(\textsf {NP}\)-complete [35, Lemma 5]. Given an arbitrary instance C of \(\text {X3SAT}_{+}^{\,=3}\), the reduction constructs an ASHG represented by its underlying graph (NE) which has binary and symmetric preferences and maximum degree 3. Together, Lemmas 2.6 and 2.8 show that this ASHG contains an envy-free partition into triples if and only if C is exactly satisfiable, and thus that this decision problem is \(\textsf {NP}\)-hard. \(\hfill\square\)

3 Weakly justified envy-freeness

In this section we consider wj-envy-freeness in ASHGs with binary and symmetric preferences.

First, in Sect. 3.1, we consider ASHGs with maximum degree 2. We show that in polynomial time we can either construct a wj-envy-free partition into triples or report that no such partition into triples exists (Theorem 3.24). In fact, we present a necessary and sufficient condition for the non-existence of a wj-envy-free partition into triples in such an ASHG (in Definition 3.1).

Next, in Sect. 3.2, we consider ASHGs with maximum degree 3. We show that such an ASHG may not contain a wj-envy-free partition into triples and the associated existence problem is \(\textsf {NP}\)-complete.

3.1 Binary and symmetric preferences with maximum degree 2

We first define a set of ASHGs, called \({\mathcal {I}}^\star\), and show that membership in the set is a sufficient condition for the non-existence of a wj-envy-free partition into triples.

Definition 3.1

\({\mathcal {I}}^\star\)

      An ASHG belongs to \({\mathcal {I}}^\star\) if and only if the underlying graph comprises

      a set of k disjoint 4-cycles and a single isolated agent, for any k where \(k \ge 2\).

The proof involves a sequence of lemmas. Consider an ASHG with binary and symmetric preferences that belongs to \({\mathcal {I}}^\star\) and its underlying graph \(({\hat{N}}, {\hat{E}})\). Label the agents in \(({\hat{N}}, {\hat{E}})\) such that \(\alpha _{4k+1}\) is an isolated agent and \((\alpha _{4i-3}, \alpha _{4i-2}, \alpha _{4i-1}, \alpha _{4i})\) is a 4-cycle for any i where \(1\le i \le k\).

Suppose \({\hat{\pi }}\) is an arbitrary partition into triples.

Lemma 3.2

If \({\hat{\pi }}\) is wj-envy-free then \(u_{t}({\hat{\pi }}) = 2\) for every triple t in \({\hat{\pi }}\).

Proof

Suppose for a contradiction that \({\hat{\pi }}\) is wj-envy-free and there exists some triple t in \({\hat{\pi }}\) such that \(u_{t}({\hat{\pi }}) \ne 2\). Since preferences are binary and symmetric, it must be that \(u_{t}({\hat{\pi }}) \in \{ 0, 4 \}\). Without loss of generality, assume that t is chosen so that \(u_{t}({\hat{\pi }})\) is minimised. Since \(\alpha _{4k+1}\) is an isolated agent, it must be that \(u_{t}({\hat{\pi }}) \le u_{{\hat{\pi }}(\alpha _{4k+1})}({\hat{\pi }}) \le 2\). The only possibility is that \(u_{t}({\hat{\pi }}) = 0\). Furthermore, without loss of generality assume that \(t = \{ \alpha _1, \alpha _i, \alpha _j \}\) where \(i > 4\) and \(j > 4\).

Since \(( \alpha _1, \alpha _2, \alpha _3, \alpha _4 )\) is a 4-cycle, if \(u_{\alpha _2}({\hat{\pi }}) = 0\) then \(\alpha _2\) has wj-envy for \(\alpha _i\), which is a contradiction. It follows that \(u_{\alpha _2}({\hat{\pi }}) \ge 1\). A symmetric argument shows that \(u_{\alpha _4}({\hat{\pi }}) \ge 1\). The only possibility is that \(\{ \alpha _2, \alpha _3, \alpha _4 \} \in {\hat{\pi }}\). Now \(\alpha _1\) has wj-envy for \(\alpha _3\), which is also a contradiction. \(\hfill\square\)

Lemma 3.3

If an ASHG belongs to \({\mathcal {I}}^\star\) then it does not contain a wj-envy-free partition into triples.

Proof

By Lemma 3.2 it must be that \(u_{t}({\hat{\pi }}) = 2\) for every triple t in \({\hat{\pi }}\) and thus that the number of agents with utility 0 is exactly n. Since \(\alpha _{4k+1}\) is isolated, the number of agents in 4-cycles with utility 0 must be exactly \((4k + 1)/3 - 1 = (4k - 2)/3\). Since \((4k - 2)/3\) is not divisible by 4, and the number of 4-cycles is k where \(k \ge 2\), the only possibility is that there exists at least one 4-cycle in which exactly two agents have utility 0, and exactly two agents have utility 1. Without loss of generality assume that this 4-cycle is \(( \alpha _1, \alpha _2, \alpha _3, \alpha _4)\) and that \(u_{\alpha _1}({\hat{\pi }}) = u_{\alpha _2}({\hat{\pi }}) = 0\) and \({\hat{\pi }}(\alpha _3) = \{ \alpha _3, \alpha _4, \alpha _i \}\) where \(i \ge 4\). Now \(\alpha _1\) has wj-envy for \(\alpha _i\), which is a contradiction. \(\hfill\square\)

We now present an algorithm that, given an ASHG with binary and symmetric preferences and maximum degree 2, either returns a wj-envy-free partition into triples \(\pi\) or reports that the ASHG belongs to \({\mathcal {I}}^\star\).

In some respects the approach taken by this algorithm is straightforward. For any path or cycle that is not a 4-cycle, it constructs as many triples as possible that each contains a path of three agents, leaving at most one or two surplus agents per component. More care is required in the assignment of the agents in 4-cycles to triples. For any set of three 4-cycles, it is relatively straightforward to assign the 12 agents to four triples in a way that ensures none of them are wj-envied as a result. The main complexity therefore stems from the case in which the number of 4-cycles is not divisible by 3. In this case the algorithm either uses the surplus agents or reports that the ASHG belongs to \({\mathcal {I}}^\star\).

The algorithm contains calls to five subroutines. In order to simplify the overall presentation, before formally describing the main algorithm we describe each subroutine and prove some related preliminary lemmas. Four of these subroutines take as input a set agents in N and construct a set of triples containing some or all of the agents in that set. The final subroutine is a helper function used to shorten the the main algorithm. In what follows, assume that (NE) is the underlying graph of an arbitrary ASHG.

The first subroutine is Subroutine nonC4Components, shown in Algorithm 1. This subroutine takes as input a set of components \({\mathcal {C}}\), none of which is a 4-cycle. It returns a pair (TS) where T is a set of triples and S is a set of surplus agents. For each component in \({\mathcal {C}}\), the corresponding set of triples in T is constructed in a straightforward way by breaking up \({\mathcal {C}}\) into triples that each contains a path of three agents. This leaves at most two surplus agents from each component, which are added to S. Note that the subgraph induced by S in (NE) has maximum degree 1.

Algorithm 1
figure a

Subroutine nonC4Components

Lemma 3.4

Subroutine nonC4Components terminates in \(O(|C'|)\) time.

Proof

Suppose \(C'\) is the set of agents in components in \({\mathcal {C}}\). By definition, there are \(|{\mathcal {C}}|\) iterations of the outer “for” loop. In each iteration of the outer loop, the subroutine identifies some component C, which has k agents. It it straightforward to show that each of the inner “for” loops involves at most O(k) iterations and each iteration of each inner “for” loop can be performed in constant time. It follows that each iteration of the outer “for” loop can be performed in O(k) time. It is then straightforward to show that the running time of Subroutine nonC4Components is \(O(|C'|)\). \(\hfill\square\)

Lemma 3.5

Suppose \(\pi\) is an arbitrary partition into triples and Subroutine \(\textsf {nonC4Components}\) returns (TS). For any agent \(c_j\) in \(\bigcup T\), if \(T(c_j) \in \pi\) then \(c_j\) is not wj-envious in \(\pi\).

Proof

Suppose some agent \(c_j\) in \(\bigcup T\) belongs to some component C in \({\mathcal {C}}\), which must not be a 4-cycle. By the construction of T in Subroutine nonC4Components, it must be that \(T(c_j)\) contains either \(c_{j-1}\) or \(c_{j+1}\). Since \(T(c_j) \in \pi\) it must be that \(u_{c_j}(\pi ) \ge 1\). If \(c_j\) has wj-envy in \(\pi\) then it must be that \(u_{c_j}(\pi ) = 1\) and two agents not in \(\pi (c_j)\) are adjacent to \(c_j\). Since \(u_{c_j}(\pi ) = 1\) it follows that the degree of \(c_j\) in (NE) is least 3, which is a contradiction. \(\hfill\square\)

Lemma 3.6

Suppose \(\pi\) is an arbitrary partition into triples and Subroutine \(\textsf {nonC4Components}\) returns (TS). For any agent \(c_j\) in \(\bigcup T\), if \(T(c_j) \in \pi\) then \(c_j\) is not wj-envied in \(\pi\).

Proof

Suppose \(c_j\) is an arbitrary agent in \(\bigcup T\). Let \(i = \lceil j/3 \rceil\). By the pseudocode of Subroutine \(\textsf {nonC4Components}\), it must be that \(T(c_j) = \{ c_{3i-2}, c_{3i-1}, c_{3i} \}\) and \(T(c_j)\) was added to T in the \(i^{th}\) iteration of the inner “for” loop, in the iteration of the outer “for” loop relating to component C. Note that by definition \(\{ c_{3i-2}, c_{3i-1} \} \in E\) and \(\{ c_{3i-1}, c_{3i} \} \in E\).

There are now three possibilities: \(j = 3i-2\), \(j=3i-1\), and \(j=3i\). Suppose for a contradiction that \(T(c_j) \in \pi\) and \(c_j\) is wj-envied in \(\pi\) by some agent \(\alpha _k\) in N. Note that since \(T(c_j) \in \pi\) it must be that \(\alpha _k \notin \{ c_{3i-2}, c_{3i-1} \}\).

First, suppose that either \(j = 3i-2\) or \(j=3i\). Since \(\alpha _k\) has wj-envy for \(c_j\) in \(\pi\), it must be that \(v_{c_{3i-1}}(\alpha _k) \ge v_{c_{3i-1}}(c_j) = 1\). It follows that \(v_{c_{3i-1}}(\alpha _k) = v_{c_{3i-1}}(c_{3i-2}) = v_{c_{3i-1}}(c_{3i}) = 1\). Since \(\alpha _k \notin \{ c_{3i-2}, c_{3i-1} \}\) it follows that that the degree of \(c_{3i-1}\) in (NE) is at least 3, which is a contradiction.

Second, suppose that \(j = 3i - 1\). Since \(\alpha _k\) has wj-envy for \(c_j\) in \(\pi\), and \(T(c_j) \in \pi\), it must be that \(v_{c_{3i-2}}(\alpha _k) \ge v_{c_{3i-2}}(c_{3i-1}) = 1\) and \(v_{c_{3i}}(\alpha _k) \ge v_{c_{3i}}(c_{3i-1}) = 1\). It follows that \(v_{c_{3i-2}}(\alpha _k) = v_{c_{3i}}(\alpha _k) = 1\). The only possibility is that \(( c_{3i-2}, c_{3i-1}, c_{3i}, \alpha _k)\) is a 4-cycle, which contradicts the fact that \({\mathcal {C}}\) is a valid input to Subroutine \(\textsf {nonC4Components}\). \(\hfill\square\)

Lemma 3.7

Subroutine nonC4Components is correct.

Proof

By Lemma 3.4, Subroutine nonC4Components eventually terminates and returns a pair (TS). By the definition of Subroutine nonC4Components, it is straightforward to show that \(C' = S \cup \bigcup T\), where \(C'\) is set of agents in components in \({\mathcal {C}}\). By Lemmas 3.5 and 3.6, if \(\pi\) is an arbitrary partition into triples then for any agent \(c_j\) in \(\bigcup T\) if \(T(c_j) \in \pi\) then \(c_j\) is neither wj-envious nor wj-envied in \(\pi\). \(\hfill\square\)

The second subroutine is Subroutine oneC4TwoSingles. This subroutine takes as input a 4-cycle R with consecutive agents labelled \((r_1, r_2, r_3, r_4)\) and two other agents \(w_1\) and \(w_2\). It returns \(\{ \{ w_1, r_1, r_2 \}, \{ w_2, r_3, r_4 \} \}\).

Lemma 3.8

For any partition into triples \(\pi\), if Subroutine oneC4TwoSingles returns \(T'\) and \(T'\subseteq \pi\) then no agent in \(R \cup \{ w_1, w_2 \}\) is wj-envied in \(\pi\).

Proof

Label \(R = ( r_1, r_2, r_3, r_4 )\) so \(T' = \{ \{ w_1, r_1, r_2 \}, \{ w_2, r_3, r_4 \} \}\). Suppose for a contradiction that some agent \(\alpha _k\) has wj-envy for some agent in \(R \cup \{ w_1, w_2 \}\). By symmetry, we need only consider two cases: either \(\alpha _k\) has wj-envy for \(r_1\) or \(\alpha _k\) has wj-envy for \(w_1\).

If \(\alpha _k\) has wj-envy for \(r_1\) then consider \(r_2\). Since \(r_2 \in \pi (r_1)\) it must be that \(v_{r_2}(\alpha _k) \ge v_{r_2}(r_1) = 1\) and thus that \(v_{r_2}(\alpha _k)=1\). The only possibility is that \(\alpha _k = r_3\). Since \(u_{r_3}(\pi ) = 1 = u_{r_3}(\{ r_1, w_2 \})\) it must be that \(r_3\) does not have wj-envy for \(r_1\), which is a contradiction.

If \(\alpha _k\) has wj-envy for \(w_1\) then it must be that \(u_{\alpha _k}(\{ r_1, r_2 \}) \ge 1\). The only possibility is that either \(\alpha _k = r_3\) or \(\alpha _k = r_4\). Since \(u_{r_3}(\pi ) = u_{r_4}(\pi ) = 1 = u_{r_3}(\{ r_1, r_2 \}) = u_{r_4}(\{ r_1, r_2 \})\) it must be that neither \(r_3\) nor \(r_4\) have wj-envy for \(w_1\), which is a contradiction. \(\hfill\square\)

The third subroutine is Subroutine multipleOfThreeC4s, shown in Algorithm 2. It takes as input a set of 4-cycles \({\mathcal {R}}\) where \(|{\mathcal {R}}|=3q\) for some integer \(q \ge 1\). It returns 4q triples, each of which contains two agents in some 4-cycle in \({\mathcal {R}}\) and one agent in a different 4-cycle in \({\mathcal {R}}\). The four agents in each 4-cycle in \({\mathcal {R}}\) are assigned to either two or four triples.

Algorithm 2
figure b

Subroutine multipleOfThreeC4s

The proof of Lemma 3.9 is straightforward.

Lemma 3.9

Subroutine multipleOfThreeC4s terminates in \(O(|{\mathcal {R}}|)\) time.

Lemma 3.10

Subroutine multipleOfThreeC4s is correct.

Proof

By Lemma 3.9, Subroutine nonC4Components eventually terminates and returns a set of triples T. By the definition of Subroutine multipleOfThreeC4s, it suffices to show that no agent in \(R_{3d} \cup R_{3d-1} \cup R_{3d-2}\) is wj-envied in \(\pi\), for any d where \(1\le d \le q\). Without loss of generality assume that \(d = 1\). In fact, by the symmetry of the four triples in T that involve agents in \(R_1\), \(R_2\), and \(R_3\), it suffices to show that no agent in \(\{ r_{1}^1, r_{1}^2, r_{2}^1 \}\) is wj-envied in \(\pi\).

First, suppose for a contradiction that some agent \(\alpha _k\) has wj-envy for \(r_1^1\). Since \(v_{r_1^2}(r_1^1) = 1\) it must be that \(v_{r_1^2}(\alpha _k) = 1\). The only possibility is that \(\alpha _k = r_1^3\). By construction, \(u_{r_1^3}(\pi ) = 1 = u_{r_1^3}(\{ r_1^2, r_2^1 \})\) so \(r_1^3\) does not have wj-envy for \(r_1^1\), which is a contradiction. A symmetric argument shows that if some \(\alpha _k\) has wj-envy for \(r_1^2\) then it must be that \(\alpha _k = r_1^4\). Since \(u_{r_1^4}(\pi ) = 1 = u_{r_1^4}(\{ r_1^1, r_2^1 \})\) this also leads to a contradiction.

Finally, suppose some agent \(\alpha _k\) has wj-envy for \(r_2^1\). It follows that \(u_{\alpha _k}(\{ r_1^1, r_1^2 \}) \ge 1\), so either \(\alpha _k = r_1^3\) or \(\alpha _k = r_1^4\). Suppose \(\alpha _k = r_1^3\). By construction, \(u_{r_1^3}(\pi ) = 1 = u_{r_1^3}(\{ r_1^1, r_1^2 \})\) so \(r_1^3\) does not have wj-envy for \(r_2^1\), which is a contradiction. A symmetric argument also leads to a contradiction if \(\alpha _k = r_1^4\). \(\hfill\square\)

The fourth subroutine is Subroutine configureSurplusAgents, shown in Algorithm 3. It takes as input a set of agents \({\hat{S}}\) where \(|{\hat{S}}|\) is divisible by three and the subgraph induced by \({\hat{S}}\) in (NE) has maximum degree 1. It returns a set of \(|{\hat{S}}|/3\) triples. When it is called in the main algorithm, this subroutine will be given a subset of the surplus agents returned by Subroutine nonC4Components. Informally, in the context of the main algorithm, the goal of this subroutine is to assign the remaining surplus agents to triples such that the number of triples with non-zero utility is maximised.

We remark that the procedure of Subroutine configureSurplusAgents is similar to a subroutine used in a similar model that constructs a stable partition into triples [11].

Algorithm 3
figure c

Subroutine configureSurplusAgents

Lemma 3.11

Subroutine configureSurplusAgents terminates in \(O(|{\hat{S}}|)\) time.

Proof

The sets of pairs \({\mathcal {X}}\) and \({\mathcal {W}}\), the set of agents Y, and the returned set of triples T can all be constructed in \(O(|{\hat{S}}|)\) time. \(\hfill\square\)

Lemma 3.12

Subroutine configureSurplusAgents is correct.

Proof

By Lemma 3.11, Subroutine configureSurplusAgents eventually terminates and returns a set of triples \(T'\). From the pseudocode of Subroutine configureSurplusAgents, it is straightforward to show that \(\bigcup T' = {\hat{S}}\). Suppose for a contradiction that \(\pi\) is an arbitrary partition into triples, \(T' \subseteq \pi\), and some agent \(\alpha _{j_1}\) in \({\hat{S}}\) has wj-envy for some agent \(\alpha _{k_1}\) in \({\hat{S}}\), where \(\pi (\alpha _{j_1}) = \{ \alpha _{j_1}, \alpha _{j_2}, \alpha _{j_3} \}\) and \(\pi (\alpha _{k_1}) = \{ \alpha _{k_1}, \alpha _{k_2}, \alpha _{k_3} \}\). It follows that \(u_{\alpha _{j_1}}(\{ \alpha _{k_2}, \alpha _{k_3} \}) \ge 1\). Without loss of generality assume that \(v_{\alpha _{j_1}}(\alpha _{k_2})=1\), meaning \(\{ \alpha _{j_1}, \alpha _{k_2} \} \in E\). By the definition of \({\mathcal {Q}}\), it must be that \(\{ \alpha _{j_1}, \alpha _{k_2} \} \in {\mathcal {Q}}\).

Now, by the pseudocode of Subroutine configureSurplusAgents, for any pair \(\{ q_a, q_b \}\) in \({\mathcal {Q}}\), if \(|{\mathcal {Q}}| < |{\hat{S}}|/3\) then \(q_a\) belongs to the same triple as \(q_b\). Since \(\alpha _{j_1}\) does not belong to the same triple as \(\alpha _{k_2}\) it must be that \(|{\mathcal {Q}}| \ge |{\hat{S}}|/3\).

By the pseudocode, for any triple in \(T'\) there exists some pair in \({\mathcal {Q}}\) that is a subset of that triple. It follows that either \(\{ \alpha _{k_1}, \alpha _{k_2} \} \in {\mathcal {Q}}\), \(\{ \alpha _{k_1}, \alpha _{k_3} \} \in {\mathcal {Q}}\), or \(\{ \alpha _{k_2}, \alpha _{k_3} \} \in {\mathcal {Q}}\). Since \(\{ \alpha _{j_1}, \alpha _{k_2} \} \in {\mathcal {Q}}\), and \({\mathcal {Q}}\) is agent-disjoint, the only possibility is that \(\{ \alpha _{k_1}, \alpha _{k_3} \} \in {\mathcal {Q}}\). By the definition of \({\mathcal {Q}}\), it must be that \(v_{\alpha _{k_1}}(\alpha _{k_3})=1\). Since \(\alpha _{j_1}\) has wj-envy for \(\alpha _{k_1}\) it must be that \(v_{\alpha _{k_3}}(\alpha _{j_1}) \ge v_{\alpha _{k_3}}(\alpha _{k_1}) = 1\). In other words, \(\{ \alpha _{k_3}, \alpha _{k_1} \} \in E\). Now, since \(\{ \alpha _{k_3}, \alpha _{k_1} \} \in E\) and \(\{ \alpha _{k_3}, \alpha _{j_1} \} \in E\) it must be that the degree of \(\alpha _{k_3}\) in the subgraph induced by \({\hat{S}}\) in (NE) is at least 2, which is a contradiction. \(\hfill\square\)

The fifth subroutine is Subroutine pickLowDegree. This subroutine takes as input a set S and integer \(k\ge 1\), such that the maximum degree of the subgraph induced by S in (NE) is 1. It returns a set of k agents in S such that the sum of the degrees of these agents in the subgraph induced by S in (NE) is minimised. Since the maximum degree of the subgraph induced by S in (NE) is 1, this subroutine can be implemented to run in O(|N|) time.

We now present the main algorithm, which we call Algorithm wjPathsCycles and define using pseudocode in Algorithm 4. Its general procedure is as follows. First, Subroutine nonC4Components is used to break up components that are not 4-cycles into a set of triples T and a set of surplus agents S, such that each triple in T contains a path of three agents. The algorithm then constructs a set \({\mathcal {R}}\) that contains the 4-cycles. If \(|{\mathcal {R}}|\) is not divisible by three then execution enters either the first or second branch of the outermost “if” statement. In the first branch, the algorithm either identifies that the ASHG belongs to \({\mathcal {I}}^\star\) or first identifies four agents, which may be surplus. Subroutine multipleOfThreeC4s is then used to assign both these four agents and the agents in two of the 4-cycles, labelled \(R_1\) and \(R_2\), to four triples. In the second branch, the algorithm first identifies two surplus agents. Subroutine multipleOfThreeC4s is then used to assign both these two surplus agents and the agents in one of the 4-cycles, labelled \(R_1\), to two triples. If \(|{\mathcal {R}}|\) is divisible by three then execution enters the third branch.

Algorithm 4
figure d

Algorithm wjPathsCycles

After execution leaves the “if” statement, the algorithm constructs a set of 4-cycles \({\mathcal {R}}'\) where \(|{\mathcal {R}}'|\) is divisible by three. It is straightforward to then assign the agents in 4-cycles in \({\mathcal {R}}'\) to triples using Subroutine multipleOfThreeC4s. Finally, any remaining surplus agents, in \({\hat{S}}\), are assigned to triples using Subroutine configureSurplusAgents.

Proposition 3.13 follows immediately by Lemma 3.7.

Proposition 3.13

In Algorithm wjPathsCycles, \(S \cup \bigcup T\) is the set of agents that do not belong to 4-cycles in (NE).

We now prove two propositions that show that, in two specific cases, S is large enough to extract the number of surplus agents required.

Proposition 3.14

In Algorithm wjPathsCycles, after initialising \({\mathcal {R}}\), if \(|{\mathcal {R}}| \bmod 3 = 2\) and \(|S| < 4\) then \(|S| = 1\).

Proof

Suppose \(|{\mathcal {R}}| \bmod 3 = 2\) and \(|S| < 4\) after initialising \({\mathcal {R}}\). Then there exists some constant \(k_1 \ge 0\) such that \(|{\mathcal {R}}| = 3{k_1} + 2\), so the number of agents in N that belong to 4-cycles is \(4|{\mathcal {R}}| = 12{k_1} + 8\). It follows that the number of agents in N that do not belong to 4-cycles is \(3n - 12{k_1} - 8\). Since \((3n - 12{k_1} - 8) \bmod 3 = 1\) there exists some constant \(k_2 \ge 0\) such that the number of agents in N that do not belong to 4-cycles is \(3{k_2} + 1\). By Proposition 3.13, \(S \cup \bigcup T\) is the set of agents in N that do not belong to 4-cycles. Since \(|S \cup \bigcup T| = 3{k_2} + 1\), T is a set of disjoint triples, and \(|S| < 4\), it must be that \({k_2}=0\) and \(|S|=1\). \(\hfill\square\)

Proposition 3.15

In Algorithm wjPathsCycles, after initialising \({\mathcal {R}}\), if \(|{\mathcal {R}}| \bmod 3 = 1\) then \(|S| \ge 2\).

Proof

Suppose \(|{\mathcal {R}}| \bmod 3 = 1\) after initialising \({\mathcal {R}}\). Then there exists some constant \({k_1} \ge 0\) such that \(|{\mathcal {R}}| = 3{k_1} + 1\), so the number of agents in N that belong to 4-cycles is \(4|{\mathcal {R}}| = 12{k_1} + 4\). It follows that the number of agents in N that do not belong to 4-cycles is \(3n - 12{k_1} - 4\). Since \((3n - 12{k_1} - 4) \bmod 3 = 2\) there exists some constant \({k_2} \ge 0\) where the number of agents in N that do not belong to 4-cycles is \(3{k_2} + 2\). By Proposition 3.13, \(S \cup \bigcup T\) is the set of agents in N that do not belong to 4-cycles. Since \(|S \cup \bigcup T| = 3{k_2} + 2\) and T is a set of disjoint triples it must be that \(|S| \ge 2\). \(\hfill\square\)

We now show that Algorithm wjPathsCycles is bound to terminate and has a linear running time with respect to the number of agents.

Lemma 3.16

Algorithm wjPathsCycles terminates in O(|N|) time.

Proof

The pseudocode describes the algorithm at a high level. To analyse the worst-case asymptotic time complexity we describe one possible system of data structures and analyse the algorithm with respect to the number of basic operations on these data structures. We begin the analysis at the start of the pseudocode.

The initialisation of \(\pi\), \({\hat{T}}\), and \({\hat{S}}\) can be performed in constant time. The set of components \({\mathcal {C}}\) that are not 4-cycles can be identified in O(|N|) time using breadth-first search, since the maximum degree of (NE) is 2.

It is straightforward to show, using Lemma 3.4, that the call to Subroutine nonC4Components takes O(|N|) time.

Like \({\mathcal {C}}\), the set of components \({\mathcal {R}}\) that are 4-cycles can be constructed in O(|N|) time. Each nested branch of the “if/else” statement involves removing a constant number of elements from S, at most two calls to Subroutine oneC4TwoSingles (which has constant running time), and an assignment to \({\hat{T}}\) and \({\hat{S}}\) (which can be performed in O(|N|) time). It follows that the total running time of the “if/else” statement is O(|N|).

By Lemma 3.9, Subroutine multipleOfThreeC4s has \(O(|{\mathcal {R}}|) = O(|N|)\) running time. By Lemma 3.11, Subroutine configureSurplusAgents has \(O(|S|) = O(|N|)\) running time. It follows that the asymptotic worst-case running time of Algorithm wjPathsCycles is O(|N|).\(\quad \square\)

Having established that Algorithm wjPathsCycles is bound to terminate, we prove its correctness using a sequence of lemmas. First we show that if the ASHG belongs to \({\mathcal {I}}^\star\) then the algorithm correctly identifies it as such.

Lemma 3.17

If the ASHG represented by (NE) belongs to \({\mathcal {I}}^\star\) then Algorithm wjPathsCycles returns “ASHG belongs to \({\mathcal {I}}^\star\)”.

Proof

Suppose the ASHG represented by (NE) belongs to \({\mathcal {I}}^\star\). In the algorithm, the set of components \({\mathcal {C}}\) that are not 4-cycles contains exactly one element \(C_1\) where \(C_1\) contains a single agent \(c_1\). By Lemma 3.7, Subroutine nonC4Components must return \((\varnothing , \{ c_1 \})\) so \(T = \varnothing\) and \(S = \{ c_1 \}\). Consider the outermost “if/else” statement in the algorithm. By the definition of \({\mathcal {I}}^\star\) (Definition 3.1), it must be that \(4|{\mathcal {R}}| + 1 \bmod 3 = 0\). It follows that \(|{\mathcal {R}}| + 1 \bmod 3 = 0\) and thus that \(|{\mathcal {R}}| \bmod 3 = 2\). It follows that the algorithm enters the first branch of the outermost “if/else” statement. Since \(|S| = 1 < 4\) and \(T = \varnothing\) the algorithm must then return “ASHG belongs to \({\mathcal {I}}^\star\)”. \(\hfill\square\)

We now consider the case in which the ASHG represented by (NE) does not belong to \({\mathcal {I}}^\star\).

Lemma 3.18

If the ASHG represented by (NE) does not belong to \({\mathcal {I}}^\star\) then Algorithm wjPathsCycles returns a partition into triples \(\pi\).

Proof

Consider an arbitrary component C in (NE). Let k be the number of agents in C. We show that each agent in C is added to exactly one triple in \(\pi\).

Suppose C is not a 4-cycle. By the definition of Algorithm wjPathsCycles, exactly one call is made to Subroutine nonC4Components with argument C. Consider an arbitrary agent \(c_i\) in C. There are two cases: either \(i \le \lfloor k/3 \rfloor\) or \(i > \lfloor k/3 \rfloor\). In the former case, exactly one triple containing \(c_i\) is added to T in Subroutine nonC4Components, which is then added to \(\pi\) in the main algorithm. In the latter case, \(c_i\) is eventually added to S. We can see from Subroutine configureSurplusAgents that \(c_i\) is therefore eventually added to exactly one triple in \(\pi\).

Suppose C is a 4-cycle, meaning \(C \in {\mathcal {R}}\). If \(C \in {\mathcal {R}}'\) then each agent in C is added to exactly one triple in \(\pi\) in some call to Subroutine multipleOfThreeC4s. If \(C \notin {\mathcal {R}}'\) then some call to Subroutine oneC4TwoSingles is made with the first argument equal to C and the returned set of two triples is then added to \(\pi\). It follows that each agent in each 4-cycle is added to exactly one triple in \(\pi\). \(\hfill\square\)

We now show that if the ASHG represented by (NE) does not belong to \({\mathcal {I}}^\star\) then the algorithm returns a partition into triples \(\pi\) that is wj-envy-free. In the next four lemmas we consider certain subsets of N and show that in each subset no agent is wj-envied in \(\pi\).

Lemma 3.19

If Algorithm wjPathsCycles returns a partition into triples \(\pi\) then no agent in \(\bigcup T\) is wj-envied in \(\pi\).

Proof

Suppose Algorithm wjPathsCycles has returned some partition into triples \(\pi\). Consider an arbitrary triple t in T. By the definition of Algorithm wjPathsCycles there are two possibilities: either \(t \in {\hat{T}}\) or t was labelled \({\hat{t}}\). If \(t \in {\hat{T}}\) then by Lemma 3.6 no agent in t is wj-envied in \(\pi\). Suppose then that t was labelled \({\hat{t}}\). By Algorithm wjPathsCycles, for any agent \(c_i\) in \({\hat{t}}\) it must be that some call was made to Subroutine oneC4TwoSingles in which the second or third argument was equal to \(c_i\) and then the two triples returned by the subroutine were added to \(\pi\). By Lemma 3.8, it follows that no agent in \({\hat{t}}\) is wj-envied in \(\pi\). \(\hfill\square\)

Lemma 3.20

If Algorithm wjPathsCycles returns a partition into triples \(\pi\) then no agent in \({\hat{S}}\) is wj-envied in \(\pi\).

Proof

Suppose Algorithm wjPathsCycles has returned some partition into triples \(\pi\) in which some agent \(\alpha _i\) has wj-envy for some agent \({\hat{s}}_{j_1}\) in \({\hat{S}}\). By the pseudocode, it must be that \(\pi ({\hat{s}}_{j_1})\) contains three agents in \({\hat{S}}\) so we label \(\pi ({\hat{s}}_{j_1}) = \{ {\hat{s}}_{j_1}, {\hat{s}}_{j_2}, {\hat{s}}_{j_3} \}\). Note that since \(|{\hat{S}}| > 0\) it must be that \({\hat{T}} = T\).

Since \(\alpha _i\) has wj-envy for \({\hat{s}}_{j_1}\) it must be that \(u_{\alpha _i}(\{ {\hat{s}}_{j_2}, {\hat{s}}_{j_3} \}) \ge 1\) so without loss of generality assume that \(\{ \alpha _i, {\hat{s}}_{j_2} \} \in E\). We now consider two possibilities: either \(\alpha _i \in S\) or \(\alpha _i \notin S\).

First, suppose \(\alpha _i \in S\). If \(\alpha _i \in {\hat{S}}\) then Lemma 3.12 is contradicted, so it must be that \(\alpha _i \in S {\setminus } {\hat{S}}\). By the pseudocode, \(\alpha _i\) was labelled either \(w_1\), \(w_2\), \(w_3\) or \(w_4\) during algorithm execution and must belong to some set of agents returned by a call to Subroutine pickLowDegree. Since \(\{ \alpha _i, {\hat{s}}_{j_2} \} \subset S\) the degree of \(\alpha _i\) in the subgraph induced by S in (NE) is 1. By the definition of Subroutine pickLowDegree it must be that the degree of each agent in \({\hat{S}}\) in (NE) is also 1. Now consider the call \(\textsf {configureSurplusAgents}({\hat{S}})\) and the execution within Subroutine configureSurplusAgents. Since the degree of each agent in \({\hat{S}}\) in (NE) is 1, it must be that \(|{\mathcal {Q}}| = |{\hat{S}}|/2 \ge |{\hat{S}}|/3\) so \({\mathcal {X}} \subset {\mathcal {Q}}\). It follows that, by the definition of Subroutine configureSurplusAgents, each triple in the set of triples returned by this subroutine contains two agents that are adjacent. It follows that either \(\{ {\hat{s}}_{j_1}, {\hat{s}}_{j_2} \} \in E\), \(\{ {\hat{s}}_{j_2}, {\hat{s}}_{j_3} \} \in E\), or \(\{ {\hat{s}}_{j_1}, {\hat{s}}_{j_3} \} \in E\). If \(\{ {\hat{s}}_{j_1}, {\hat{s}}_{j_2} \} \in E\) or \(\{ {\hat{s}}_{j_2}, {\hat{s}}_{j_3} \} \in E\) then the degree of \({\hat{s}}_{j_2}\) in the subgraph induced by S in (NE) is 2, which is a contradiction. It remains that \(\{ {\hat{s}}_{j_1}, {\hat{s}}_{j_3} \} \in E\). Since \(\alpha _i\) has wj-envy for \({\hat{s}}_{j_1}\) it must be that \(v_{{\hat{s}}_{j_3}}(\alpha _i) \ge v_{{\hat{s}}_{j_3}}({\hat{s}}_{j_1}) = 1\). It follows that the degree of \({\hat{s}}_{j_3}\) in the subgraph induced by S in (NE) is at least 2, which is a contradiction.

Second, suppose \(\alpha _i \notin S\). Since \(\{ \alpha _i, {\hat{s}}_{j_2} \} \in E\), by the definition of Algorithm wjPathsCycles it must be that \(\alpha _i\) belongs to the same component in (NE) as \({\hat{s}}_{j_2}\). Since \({\hat{s}}_{j_2}\in S\), by the pseudocode of Algorithm wjPathsCycles it must be that the component that contains \(\alpha _i\) and \({\hat{s}}_{j_2}\) is not a 4-cycle so belongs to \({\mathcal {C}}\). Since \(\alpha _i \notin S\), by Lemma 3.7 it must be that some triple in T contains \(\alpha _i\). Since \(T = {\hat{T}}\) it follows that \(T(c_j) = {\hat{T}}(c_j)\) belongs to \(\pi\), so by Lemma 3.5\(\alpha _i\) is not wj-envious in \(\pi\), which is a contradiction. \(\hfill\square\)

Lemma 3.21

If Algorithm wjPathsCycles returns a partition into triples \(\pi\) then no agent in S is wj-envied in \(\pi\).

Proof

Suppose Algorithm wjPathsCycles has returned some partition into triples \(\pi\). Consider an arbitrary agent \(s_i\) in S. If \(s_i \in {\hat{S}}\) then by Lemma 3.20 it must be that \(s_i\) is not wj-envied in \(\pi\). It remains that \(s_i \notin {\hat{S}}\). There are three cases: either \(|{\mathcal {R}}|\bmod 3 = 2\), \(|S|\ge 4\), and \(s_i\) was labelled \(w_1\), \(w_2\), \(w_3\), or \(w_4\); \(|{\mathcal {R}}|\bmod 3 = 2\), \(|T| \ge 1\), and \(s_i\) was labelled \(w_1\); or \(|{\mathcal {R}}|\bmod 3 = 1\) and \(s_i\) was labelled either \(w_1\) or \(w_2\). In each of the three cases, some call was then made to Subroutine oneC4TwoSingles in which the second or third argument was \(s_i\) and then two triples returned by the subroutine were added to \(\pi\). By Lemma 3.8 it follows that \(s_i\) is not wj-envied in \(\pi\). \(\hfill\square\)

Lemma 3.22

If Algorithm wjPathsCycles returns a partition into triples \(\pi\) then no agent in any component in \({\mathcal {R}}\) is wj-envied in \(\pi\).

Proof

Consider an arbitrary \(R_j\) in \({\mathcal {R}}\). We show that no agent in \(R_j\) is wj-envied in \(\pi\). In this case, let \(l'\) be the final value assigned to the variable l before the algorithm terminated. There are two possibilities: either \(j>l'\) or \(j\le l'\).

Suppose \(j>l'\). It must be that \(R_j \in {\mathcal {R}}'\), by the construction of \({\mathcal {R}}'\) in Algorithm wjPathsCycles. By Lemma 3.10, it follows that no agent in \(R_j\) is wj-envied in \(\pi\).

It remains that \(j\le l'\). By the design of Algorithm wjPathsCycles there are two possibilities: either \(|{\mathcal {R}}| \bmod 3 = 2\) and \(l'=2\), or \(|{\mathcal {R}}| \bmod 3 = 1\) and \(l'=1\). In either case, by the definition of Algorithm wjPathsCycles it must be that some call to Subroutine oneC4TwoSingles was made with the first argument \(R_j\), after which the returned set of two triples was added to \(\pi\). It follows by Lemma 3.8 that no agent in \(R_j\) is wj-envied in \(\pi\).\(\hfill\square\)

Lemma 3.23

If the ASHG represented by (NE) does not belong to \({\mathcal {I}}^\star\) then Algorithm wjPathsCycles returns a partition into triples \(\pi\) that is wj-envy-free.

Proof

By Lemma 3.18, Algorithm wjPathsCycles returns a partition into triples \(\pi\). By Lemma 3.7, \(S \cup \bigcup T\) contains each agent in a component in \({\mathcal {C}}\). It follows by Lemmas 3.21 and 3.19 that no agent in \({\mathcal {C}}\) is wj-envied in \(\pi\). In addition, by Lemma 3.22, no agent in any component in \({\mathcal {R}}\) is wj-envied in \(\pi\). Since \({\mathcal {C}} \cup {\mathcal {R}}\) is the set of all components in (NE), it then follows that no agent in N is wj-envied in \(\pi\). \(\hfill\square\)

We can now prove the main theorem.

Theorem 3.24

Consider an ASHG with binary and symmetric preferences and maximum degree 2. There exists an O(|N|)-time algorithm that either finds a wj-envy-free partition into triples in the instance or reports that the instance belongs to \({\mathcal {I}}^\star\), and thus contains no such partition.

Proof

Lemma 3.16 shows that Algorithm wjPathsCycles terminates in O(|N|) time. Lemmas 3.17 and 3.23 establish the correctness of this algorithm and show that the algorithm either returns a wj-envy-free partition into triples or reports “ASHG belongs to \({\mathcal {I}}^\star\)”. In the latter case, Lemma 3.3 shows that this ASHG contains no wj-envy-free partition into triples. \(\hfill\square\)

3.2 Binary and symmetric preferences with maximum degree 3

As before in Sect. 2.2, in this section we consider ASHGs with binary and symmetric preferences and maximum degree 3. We show that deciding if a given ASHG contains a wj-envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are binary and symmetric and the maximum degree is 3.

Also as before, we reduce from \(\text {X3SAT}_{+}^{\,=3}\). Recall that by definition \(|X(C)|=m\). In this section we assume that the number of clauses m satisfies \(m=4l\) for some integer \(l\ge 1\). We can show that \(\text {X3SAT}_{+}^{\,=3}\) remains \(\textsf {NP}\)-complete under this restriction as follows. Construct four distinct copies of the set of variables X(C) and formula C. Construct a new formula \(C'\) as the union of the four copies of C. It is straightforward to show that \(C'\) is exactly satisfiable if and only if each of the four copies is exactly satisfiable, which is true if and only if the original formula C is exactly satisfiable. Note that since \(|X(C)|=m=4\,l\) it must be that l is divisible by 3.

The overall design of this reduction is similar to the analogous reduction in Sect. 2.2. The main difference between the two is in that here we associate true literals with closed variable gadgets and false literals with open variable gadgets. Another difference is that we construct a number of so-called garbage collector gadgets.

The reduction, illustrated in Fig. 4, is as follows. Suppose C is an arbitrary instance of \(\text {X3SAT}_{+}^{\,=3}\). We shall construct an ASHG represented by an underlying graph (NE).

For each variable \(x_i\) in X(C), construct a set of three agents \(W_i = \{ w_i^1, w_i^2, w_i^3 \}\), which we refer to as the \(i^{th}\) variable gadget. Add edges \(\{ w_i^1, w_i^2 \}\), \(\{ w_i^2, w_i^3 \}\), and \(\{ w_i^3, w_i^1 \}\). Next, for each clause \(c_r\) in C construct a set of four agents \(D_r = \{ d_r^1, d_r^2, d_r^3, d_r^4 \}\), which we refer to as the \(r^{th}\) clause gadget. Add edges \(\{ d_r^1, d_r^4 \}\), \(\{ d_r^2, d_r^4 \}\), and \(\{ d_r^3, d_r^4 \}\). Construct a set of 12l agents labelled \(g_1, g_2, \dots , g_{12l}\). For any i where \(1\le i\le 3\,l\), we shall refer to \(G_i = \{ g_{4i-3}, g_{4i-2}, g_{4i-1}, g_{4i} \}\) as the \(i^{th}\) garbage collector gadget. For each such i, Add edges \(\{ g_{4i}, g_{4i-1} \}\), \(\{ g_{4i}, g_{4i-2} \}\), and \(\{ g_{4i}, g_{4i-3} \}\). We remark that there are now \(40\,l\) agents.

We shall connect the variable and clause gadgets in a similar way as in the reduction in Sect. 2.2. Consider each clause \(c_r = \{ x_i, x_j, x_k \}\). If \(c_r\) contains the \(j^{th}\) occurrence of \(x_i\) then add the edge \(\{ d_r^1, w_i^j \}\). Similarly, add an edge between \(d_r^2\) and an agent in \(W_j\) depending on the index of the occurrence of \(x_j\) in the clause \(c_r\) and an edge between \(d_r^3\) and an agent in \(W_k\) depending on the index of the occurrence of \(x_k\) in the clause \(c_r\).

The construction of (NE) is now complete. Note that each agent in a variable gadget has degree 3. For any r where \(1 \le r \le m\), \(d_r^4\) has degree 3 and each of \(d_r^1\), \(d_r^2\), and \(d_r^3\) has degree 2. For any i where \(1\le i\le 3\,l\), \(g_{4i}\) has degree 3 and each of \(g_{4i-3}\), \(g_{4i-2}\), and \(g_{4i-1}\) has degree 1. It follows that the maximum degree of (NE) is 3.

It is straightforward to show that this reduction can be performed in polynomial time. To prove that the reduction is correct we show that the ASHG represented by (NE) contains a wj-envy-free partition into triples if and only if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable.

Fig. 4
figure 4

The reduction from \(\text {X3SAT}_{+}^{\,=3}\) to the problem of deciding if a given ASHG contains a wj-envy-free partition into triples. A variable gadget \(W_i\), clause gadget \(D_r\), and garbage collector gadget \(G_i\) are represented as undirected graphs

We first prove an ancillary lemma. Recall that for any set of agents S, \(\sigma (S, \pi )\) is the number of triples in \(\pi\) that each contains at least one agent in S. Recall also that for any agent \(\alpha _i\) we write \({\mathcal {N}}(\alpha _i)\) to mean the open neighbourhood of \(\alpha _i\).

Lemma 3.25

Suppose \(\pi\) is a partition into triples in the ASHG represented by (NE). For any agent \(\alpha _i\), if \(u_{\alpha _i}(\pi )=1\) and \(\sigma ({\mathcal {N}}(\alpha _i), \pi )=\deg (\alpha _i)\) then \(\alpha _i\) is not wj-envious in \(\pi\).

Proof

As for Lemma 2.4 in Sect. 2.2. \(\hfill\square\)

We now show that if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable then the ASHG represented by (NE) contains a wj-envy-free partition into triples.

Lemma 3.26

If C is exactly satisfiable then the ASHG represented by (NE) contains a wj-envy-free partition into triples.

Proof

Suppose f is an exact model of C. We shall construct a partition into triples \(\pi\) that is wj-envy-free. For each variable \(x_i\) in X(C) where \(f(x_i)\) is true, add \(\{ w_i^1, w_i^2, w_i^3 \}\) to \(\pi\). Now consider each clause \(c_r = \{ x_i, x_j, x_k \}\) and the corresponding clause gadget \(D_r\), labelling ijk such that \(W_i\) contains an agent adjacent to \(d_r^1\), \(W_j\) contains an agent adjacent to \(d_r^2\), and \(W_k\) contains an agent adjacent to \(d_r^3\). There are three cases: \(f(x_i)\) is true while both \(f(x_j)\) and \(f(x_k)\) are false, \(f(x_j)\) is true while both \(f(x_i)\) and \(f(x_k)\) are false, and \(f(x_k)\) is true while both \(f(x_i)\) and \(f(x_j)\) are false. In the first case, suppose \(c_r\) contains the \(a^{th}\) occurrence of \(x_j\) and the \(b^{th}\) occurrence of \(x_k\). Add to \(\pi\) the triples \(\{ d_r^1, d_r^4, g_{3r} \}\), \(\{ d_r^2, w_j^a, g_{3r-1} \}\), and \(\{ d_r^3, w_k^b, g_{3r-2} \}\). The constructions in the second and third cases are symmetric: in the second case, suppose \(c_r\) contains the \(a^{th}\) occurrence of \(x_i\) and the \(b^{th}\) occurrence of \(x_k\). Add to \(\pi\) the triples \(\{ d_r^2, d_r^4, g_{3r} \}\), \(\{ d_r^1, w_i^a, g_{3r-1} \}\), and \(\{ d_r^3, w_k^b, g_{3r-2} \}\). In the third case, suppose \(c_r\) contains the \(a^{th}\) occurrence of \(x_i\) and the \(b^{th}\) occurrence of \(x_j\). Add to \(\pi\) the triples \(\{ d_r^3, d_r^4, g_{3r} \}\), \(\{ d_r^1, w_i^a, g_{3r-1} \}\), and \(\{ d_r^2, w_j^b, g_{3r-2} \}\).

The construction of \(\pi\) is now complete. Note that there are three kinds of triple in \(\pi\). Specifically, for any triple t in \(\pi\), either \(t = W_i\) for some variable gadget \(W_i\); \(t = \{ d_r^4, d_r^a, g_{3r} \}\) where \(1\le r\le m\) and \(1\le a \le 3\); or \(t = \{ d_r^a, w_i^b, g_j \}\) where \(1\le i \le m\), \(1\le r \le m\), \(1\le a \le 3\), \(1\le b \le 3\), and \(1\le j\le 12\,l\). We will show that in each case no agent in t is envious.

First, consider some triple t in \(\pi\) of the first kind, where \(t = W_i\) for some variable gadget \(W_i\). Since each agent in t has utility 2, clearly no agent in t is envious.

Second, consider some triple t in \(\pi\) of the second kind, where \(t=\{ d_r^4, d_r^a, g_{3r} \}\), \(1\le r\le m\), and \(1\le a \le 3\). By the construction of \(\pi\), it must be that \(\sigma ({\mathcal {N}}(d_r^4), \pi ) = 3\). Since \(u_{d_r^4}(\pi )=1\), it follows by Lemma 3.25 that \(d_r^4\) is not envious. Similarly, since \(\pi (d_r^a)=\{ d_r^4, d_r^a, g_{3r} \}\) it follows that \(\sigma ({\mathcal {N}}(d_r^a), \pi ) = \deg (d_r^a) = 2\). Since \(u_{d_r^a}(\pi )=1\) it follows by Lemma 3.25 that \(d_r^a\) is also not envious. Now suppose for a contradiction that \(g_{3r}\) is wj-envious and has wj-envy for some agent \(\alpha _j\). It must be that \(u_{g_{3r}}(\pi (\alpha _j) {\setminus } \{ \alpha _j \})\ge 1\) so \(\pi (\alpha _j)\) must contain some agent \(g_q\) where \(\{ g_{3r}, g_q \} \in E\). Label \(\pi (\alpha _j) = \{ \alpha _j, g_q, \alpha _k \}\). By the construction of \(\pi\), the only possibility is that \(\{ \alpha _j, \alpha _k \} \subset D_s\) for some clause gadget \(D_s\), where \(u_{\alpha _j}(\pi ) = u_{\alpha _k}(\pi ) = 1\). It follows that \(\{ \alpha _k, g_q \} \notin E\) and thus that \(u_{\alpha _k}(\pi ) = u_{\alpha _k}(\{ \alpha _j, g_q \}) = 1 > 0 = u_{\alpha _k}(\{ g_q, g_{3r} \})\), which contradicts the fact that \(g_{3r}\) has wj-envy for \(\alpha _j\).

Third, consider some triple t in \(\pi\) of the third kind, where \(t=\{ d_r^a, w_i^b, g_j \}\), \(1\le i \le m\), \(1\le r \le m\), \(1\le a \le 3\), \(1\le b \le 3\), and \(1\le j\le 12\,l\). By construction, \(\sigma ({\mathcal {N}}(w_i^b), \pi ) = \deg (w_i^b) = 3\) and \(u_{w_i^b}(\pi ) \ge 1\) so it follows by Lemma 3.25 that \(w_i^b\) is not envious. Similarly, since \(\pi (d_r^a)=\{ d_r^a, w_i^b, g_{j} \}\) it follows that \(\sigma ({\mathcal {N}}(d_r^a), \pi ) = \deg (d_r^a) = 2\). Since \(u_{d_r^a}(\pi )=1\) it follows by Lemma 3.25 that \(d_r^a\) is not envious. As before, suppose for a contradiction that \(g_{j}\) is wj-envious and has wj-envy for some agent \(\alpha _k\). It must be that \(u_{g_{j}}(\pi (\alpha _k) {\setminus } \{ \alpha _k \})\ge 1\) so \(\pi (\alpha _k)\) must contain some agent \(g_q\) where \(\{ g_{j}, g_q \} \in E\). Label \(\pi (\alpha _k) = \{ \alpha _k, g_q, \alpha _h \}\). By construction of \(\pi\), the only possibility is that \(\{ \alpha _k, \alpha _h \} \subset D_s\) for some clause gadget \(D_s\), where \(u_{\alpha _k}(\pi ) = u_{\alpha _h}(\pi ) = 1\). It follows that \(\{ \alpha _h, g_q \} \notin E\) and thus that \(u_{\alpha _h}(\pi ) = u_{\alpha _h}(\{ \alpha _k, g_q \}) = 1 > 0 = u_{\alpha _h}(\{ g_q, g_j \})\), which contradicts the fact that \(g_j\) has wj-envy for \(\alpha _k\). \(\hfill\square\)

We now show, using a sequence of lemmas, that if the ASHG represented by (NE) contains a wj-envy-free partition into triples then the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable.

Lemma 3.27

If the ASHG represented by (NE) contains a wj-envy-free partition into triples \(\pi\) then \(u_{g_i}(\pi )=0\) for any i where \(1\le i\le 12l\).

Proof

Suppose \(\pi\) is a wj-envy-free partition into triples.

By the construction of (NE), the structure of each garbage collector gadget \(G_i\) is identical. Thus, to simplify the proof assume without loss of generality that \(G_i = G_1 = \{ g_1, g_2, g_3, g_4 \}\). We shall prove that \(\sigma (G_1, \pi )=4\), from which it follows directly that \(u_{g_1}(\pi )=u_{g_2}(\pi )=u_{g_3}(\pi )=u_{g_4}(\pi )=0\).

Since \(|G_1|=4\) by definition \(\sigma (G_1, \pi ) \le 4\). Suppose for a contradiction that \(\sigma (G_1, \pi ) \le 3\). Then there exist two agents \(g_a, g_b\) in \(G_1\) in the same triple in \(\pi\). Label the third agent in that triple as \(\alpha _j\).

By symmetry, we need only consider two cases. In the first case \(a=1\) and \(b=4\). In the second case \(a=1\) and \(b=2\). First, suppose \(a=1\) and \(b=4\). Since \(\{ g_1, g_4 \} \subset \pi (g_4)\), by construction it must be that either \(u_{g_2}(\pi )=0\) or \(u_{g_3}(\pi )=0\). Assume without loss of generality that \(u_{g_2}(\pi )=0\). It follows that \(g_2\) wj-envies \(\alpha _j\), since \(u_{g_2}(\pi ) = 0 < 1 = u_{g_2}(\{ g_1, g_4 \})\), \(u_{g_1}(\{ g_4, \alpha _j \}) = 1 = u_{\alpha _j}(\{ g_4, g_2 \})\), and \(u_{g_4}(\{ g_1, \alpha _j \}) = 1 < 2 = u_{g_4}(\{ g_1, g_2 \})\).

Second, suppose \(a=1\) and \(b=2\). There are two cases: either \(g_4 = \alpha _j\) or \(g_4\ne \alpha _j\). If \(g_4=\alpha _j\) then \(g_3\) wj-envies \(g_2\), since \(u_{g_3}(\pi ) = 0 < 1 = u_{g_3}(\{ g_1, g_4 \})\), \(u_{g_1}(\{ g_2, g_4 \}) = 1 = u_{g_1}(\{ g_3, g_4 \})\), and \(u_{g_4}(\{ g_1, g_2 \}) = 2 = u_{g_4}(\{ g_1, g_3 \})\). On the other hand, if \(g_4 \ne \alpha _j\) then it must be that \(u_{g_4}(\pi ) \le 1\). Now \(g_4\) wj-envies \(\alpha _j\), since \(u_{g_4}(\pi ) \le 1 < 2 = u_{g_4}(\{ g_1, g_2 \})\), \(u_{g_1}(\pi ) = 0 < 1 = u_{g_1}(\{ g_2, g_4 \})\), and \(u_{g_2}(\pi ) = 0 < 1 = u_{g_2}(\{ g_1, g_4 \})\). \(\hfill\square\)

As before in Sect. 2.2, for any partition into triples \(\pi\) and any variable gadget \(W_i\), if \(\sigma (W_i, \pi ) = 3\) then let us say that \(W_i\) is open. If \(\sigma (W_i, \pi ) = 1\) then let us say that \(W_i\) is closed.

Lemma 3.28

If the ASHG represented by (NE) contains a wj-envy-free partition into triples \(\pi\) then any variable gadget is either open or closed.

Proof

The proof is essentially the same as for Lemma 2.7. In short, if some triple in \(\pi\) contains exactly two agents in \(W_i\) then the third agent in \(W_i\) is wj-envious. \(\hfill\square\)

For any set of agents S and any clause gadget \(D_r\), let us say that S intersects \(D_r\), and vice-versa, if \(|t \cap D_r| \ge 1\).

Lemma 3.29

If the ASHG represented by (NE) contains a wj-envy-free partition into triples \(\pi\) then for any i where \(1\le i\le 12\,l\) it must be that \(\pi (g_i)\) intersects some clause gadget and \(\pi (g_i) = \{ g_i, \alpha _a, \alpha _b \}\) where \(\{ \alpha _a, \alpha _b \} \in E\).

Proof

Suppose \(\pi\) is a wj-envy-free partition into triples. Consider an arbitrary \(g_i\) where \(1\le i \le 12\,l\), labelling \(\pi (g_i) = \{ g_i, \alpha _a, \alpha _b \}\). There must exist some agent \(g_j\) such that \(\{ g_i, g_j \} \in E\). By Lemma 3.27, \(u_{g_i}(\pi ) = u_{g_j}(\pi ) = 0\).

Suppose for a contradiction that \(\{ \alpha _a, \alpha _b \} \notin E\). It follows that \(u_{\alpha _a}(\pi ) = u_{\alpha _b}(\pi ) = u_{g_i}(\pi ) = 0\). Now \(g_j\) wj-envies \(\alpha _a\), since \(u_{g_j}(\pi ) = 0 < 1 \le u_{g_j}(\{ g_i, \alpha _b \})\), \(u_{g_i}(\pi ) = 0 < 1 \le u_{g_i}(\{ g_j, \alpha _b \})\), and \(u_{\alpha _b}(\pi ) = 0 < 1 \le u_{\alpha _b}(\{ g_i, g_j\})\).

We have now shown that \(\{ \alpha _a, \alpha _b \} \in E\). Suppose for a contradiction that \(\pi (g_i)\) does not intersect any clause gadget. It must be that \(\alpha _a\) and \(\alpha _b\) both belong to variable gadgets. In fact, since \(\{ \alpha _a, \alpha _b \} \in E\) it must be that both \(\alpha _a\) and \(\alpha _b\) belong to the same variable gadget. Since \(g_i\) belongs to a garbage collector gadget, this contradicts Lemma 3.28. \(\hfill\square\)

Lemma 3.30

If the ASHG represented by (NE) contains a wj-envy-free partition into triples then C is exactly satisfiable.

Proof

Suppose \(\pi\) is a wj-envy-free partition into triples (NE). By Lemma 3.28, any variable gadget is either open or closed. Construct a truth assignment f in C by setting \(f(x_i)\) to be true if \(W_i\) is closed and false otherwise. Each variable \(x_i\) corresponds to exactly one variable gadget so it follows that f is a valid truth assignment. By the construction of (NE), each clause \(c_r\) corresponds to exactly one clause gadget \(D_r\). Recall that each clause gadget is adjacent to three variable gadgets that correspond to the three variables in that clause. To show that f is an exact model of C, it is now sufficient to show that each clause gadget is adjacent to exactly one closed variable gadget.

By Lemma 3.29, for any i where \(1\le i\le 12l\) there exists some triple \(\pi (g_i) = \{ g_i, \alpha _a, \alpha _b \}\) where \(\{ \alpha _a, \alpha _b \} \in E\) and \(\pi (g_i)\) intersects some clause gadget. Let \(T \subset \pi\) be the set of 12l such triples. Since each clause gadget contains four agents, by the definition of T it is impossible for any clause gadget to intersect four or more triples in T. It follows that any clause gadget intersects at most three triples in T. Since \(|T|=12l\) and there are exactly \(m=4l\) clause gadgets, it must be that there are on average \(12l/4l=3\) triples in T that intersect each clause gadget.

It follows that each clause gadget intersects exactly three triples in T. In fact, by the construction of each clause gadget, the only possibility is that each clause gadget \(D_r\) intersects exactly three triples in T and exactly two of these triples each intersect some variable gadget that is adjacent to \(D_r\) and must be open. It follows that each clause gadget is adjacent to exactly two open variable gadgets and exactly one closed variable gadget, as desired. \(\hfill\square\)

We have now shown that the ASHG represented by (NE) contains a wj-envy-free partition into triples if and only if the \(\text {X3SAT}_{+}^{\,=3}\) instance C is exactly satisfiable. This shows that the reduction is correct.

Theorem 3.31

Deciding if a given ASHG contains a wj-envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are binary and symmetric and maximum degree is 3.

Proof

It is straightforward to show that this decision problem belongs to \(\textsf {NP}\), since for any two agents \(\alpha _i\) and \(\alpha _j\) in N we can test if \(\alpha _i\) wj-envies \(\alpha _j\) in constant time.

We have presented a polynomial-time reduction from \(\text {X3SAT}_{+}^{\,=3}\), which is \(\textsf {NP}\)-complete [35, Lemma 5]. Given an arbitrary instance C of \(\text {X3SAT}_{+}^{\,=3}\), the reduction constructs an ASHG represented by its underlying graph (NE) which has binary and symmetric preferences and maximum degree 3. Together, Lemmas 3.26 and 3.30 show that this ASHG contains a wj-envy-free partition into triples if and only if C is exactly satisfiable, and thus that this decision problem is \(\textsf {NP}\)-hard. \(\hfill\square\)

4 Justified envy-freeness

In this section we consider j-envy-freeness.

We begin, in Sect. 4.1, by noting that any stable partition is j-envy-free. We recall a previous result that if preferences are binary and symmetric then a stable partition into triples must exist and can be found in polynomial time. We observe that a j-envy-free partition must therefore also exist and can also be found in polynomial time (Observation 4.1). We then strengthen this result to show that a j-envy-free partition into triples must exist and can be found in polynomial time when preferences are binary, but not necessarily symmetric (Theorem 4.3). As we shall see, this contrasts with an analogous result for stability.

Next, in Sect. 4.2, we consider ASHGs with ternary preferences. We show that, in general, such an ASHG may not contain a j-envy-free partition into triples, and the associated existence problem is \(\textsf {NP}\)-complete (Theorem 4.12).

Finally, in Sect. 4.3, we consider ASHGs with symmetric, non-binary preferences. As before, we show that such an ASHG may not contain a j-envy-free partition into triples, and the associated existence problem is \(\textsf {NP}\)-complete (Theorem 4.16).

4.1 Binary preferences

It is straightforward to show that if there exists an agent with j-envy then there exists a blocking triple. It follows that if a partition into triples is stable then it is j-envy-free. If preferences are binary and symmetric then a stable partition into triples must exist and can be constructed in polynomial time [11]. Observation 4.1 follows directly.

Observation 4.1

Given an ASHG with binary and symmetric preferences, a j-envy-free partition into triples always exists and can be found in polynomial time.

It is known that if preferences are binary but not necessarily symmetric then a stable partition into triples may not exist and the associated decision problem is \(\textsf {NP}\)-complete [11]. Interestingly, in contrast we now show that a j-envy-free partition into triples is bound to exist and can be found in polynomial time.

To do this, we consider a simple algorithm that involves iteratively “satisfying” any agent with j-envy. We show that this algorithm terminates in polynomial time using a standard proof technique involving a potential function [24], which strictly increases after each iteration and is polynomial in terms of the problem input. Informally, the potential function that we define here is “the total number of pairs of agents that belong to the same triple and have a mutual non-zero valuation”.

Formally, the algorithm is as follows. Suppose (NV) is an ASHG with binary preferences. First let \(\pi\) be an arbitrary partition into triples. While there exists some agent \(\alpha _i\) that has j-envy in (NV) for some other agent \(\alpha _j\), swap \(\alpha _i\) and \(\alpha _j\) in the partition. Once there is no such \(\alpha _i\), return \(\pi\), which must be j-envy-free.

To prove that this algorithm terminates in polynomial time, we define some new terminology. For any two agents \(\alpha _i\) and \(\alpha _j\) in N, we say that \(\{ \alpha _i, \alpha _j \}\) is a bidirected pair if \(v_{\alpha _i}(\alpha _j) = v_{\alpha _j}(\alpha _i) = 1\). For any set of agents S, if both \(\alpha _i\) and \(\alpha _j\) belong to S then we say that \(\{ \alpha _i, \alpha _j \}\) is a bidirected pair in S. For some partition into triples \(\pi\), let the number of bidirected pairs in \(\pi\) be the total of the number of bidirected pairs in each triple in \(\pi\).

We show in Lemma 4.2 that after each swap, the total number of bidirected pairs in \(\pi\) strictly increases.

Lemma 4.2

If \(\pi _1\) is the partition before some swap and \(\pi _2\) is the partition after that swap then the number of bidirected pairs in \(\pi _2\) is strictly greater than the number of bidirected pairs in \(\pi _1\).

Proof

Without loss of generality, assume that \(\alpha _1\) swaps with \(\alpha _4\), where \(\pi _1(\alpha _1) = \{ \alpha _1, \alpha _2, \alpha _3 \}\) and \(\pi _1(\alpha _4) = \{ \alpha _4, \alpha _5, \alpha _6 \}\), so that \(\pi _2(\alpha _1) = \{ \alpha _1, \alpha _5 \alpha _6 \}\) and \(\pi _2(\alpha _4) = \{ \alpha _4, \alpha _2, \alpha _3 \}\). It is straightforward to show that the number of bidirected pairs in \(\pi _2\) is strictly greater than the number of bidirected pairs in \(\pi _1\) if the number of bidirected pairs in \(\{ \{\alpha _1, \alpha _5\}, \{\alpha _1, \alpha _6\}, \{\alpha _4, \alpha _1\}, \{\alpha _4, \alpha _2\} \}\) is strictly greater than the number of bidirected pairs in \(\{ \{\alpha _1, \alpha _2\}, \{\alpha _1, \alpha _3\}, \{\alpha _4, \alpha _5\}, \{\alpha _4, \alpha _6\} \}\).

Since \(\alpha _1\) has j-envy for \(\alpha _4\) in \(\pi _1\) it must be that \(2 \ge u_{\alpha _1}(\pi _2) = u_{\alpha _1}(\{ \alpha _5, \alpha _6 \}) > u_{\alpha _1}(\pi _1) = u_{\alpha _1}(\{ \alpha _2, \alpha _3 \}) \ge 0\). Note that since preferences in (NV) are binary, it must also be that \(v_{\alpha _{5}}(\alpha _{1}) = v_{\alpha _{6}}(\alpha _{1}) = 1 > 0 = v_{\alpha _{5}}(\alpha _{4}) = v_{\alpha _{6}}(\alpha _{4})\). It follows that neither \(\{ \alpha _4, \alpha _5 \}\) nor \(\{ \alpha _4, \alpha _6 \}\) is a bidrected pair. There are now two possibilities: either \(u_{\alpha _1}(\{ \alpha _5, \alpha _6 \}) = 1\) or \(u_{\alpha _1}(\{ \alpha _5, \alpha _6 \}) = 2\).

First, suppose \(u_{\alpha _1}(\{ \alpha _5, \alpha _6 \}) = 1\). It must be that either \(v_{\alpha _1}(\alpha _5) = 1\) or \(v_{\alpha _1}(\alpha _6) = 1\). Without loss of generality assume that \(v_{\alpha _1}(\alpha _5) = 1\). Since \(\alpha _1\) has j-envy for \(\alpha _4\) it must be that \(u_{\alpha _1}(\pi _1) = u_{\alpha _1}(\{ \alpha _2, \alpha _3 \}) = 0 < 1 = u_{\alpha _1}(\{ \alpha _5, \alpha _6 \})\). It follows that neither \(\{\alpha _1, \alpha _2 \}\) nor \(\{\alpha _1, \alpha _3 \}\) is a bidirected pair. Since \(v_{\alpha _1}(\alpha _5) = v_{\alpha _5}(\alpha _1) = 1\) it follows that \(\{ \alpha _1, \alpha _5 \}\) is a bidirected pair and thus that the number of bidirected pairs in \(\{ \{\alpha _1, \alpha _5\}, \{\alpha _1, \alpha _6\}, \{\alpha _4, \alpha _1\}, \{\alpha _4, \alpha _2\} \}\) is strictly greater than the number of bidirected pairs in \(\{ \{\alpha _1, \alpha _2\}, \{\alpha _1, \alpha _3\}, \{\alpha _4, \alpha _5\}, \{\alpha _4, \alpha _6\} \}\), as required.

Second, suppose \(u_{\alpha _1}(\{ \alpha _5, \alpha _6 \}) = 2\). Since \(v_{\alpha _{5}}(\alpha _{1}) = v_{\alpha _{6}}(\alpha _{1}) = 1\) it must be that both \(\{ \alpha _1, \alpha _5 \}\) and \(\{ \alpha _1, \alpha _6 \}\) are bidirected pairs. Since \(\alpha _1\) has j-envy for \(\alpha _4\) it must be that \(u_{\alpha _1}(\pi _1) = u_{\alpha _1}(\{ \alpha _2, \alpha _3 \}) < 2 = u_{\alpha _1}(\{ \alpha _5, \alpha _6 \})\). It follows that either \(v_{\alpha _1}(\alpha _2) = 0\) or \(v_{\alpha _1}(\alpha _3) = 0\). The only possibility is that at most one of \(\{ \alpha _1, \alpha _2 \}\) and \(\{ \alpha _1, \alpha _3 \}\) is a bidirected pair. The number of bidirected pairs in \(\{ \{\alpha _1, \alpha _5\}, \{\alpha _1, \alpha _6\}, \{\alpha _4, \alpha _1\}, \{\alpha _4, \alpha _2\} \}\) is therefore strictly greater than the number of bidirected pairs in \(\{ \{\alpha _1, \alpha _2\}, \{\alpha _1, \alpha _3\}, \{\alpha _4, \alpha _5\}, \{\alpha _4, \alpha _6\} \}\), as required. \(\hfill\square\)

Theorem 4.3

Given an ASHG with binary preferences, a j-envy-free partition into triples must exist and can be found in polynomial time.

Proof

By Lemma 4.2, after each swap the number of bidirected pairs in \(\pi\) strictly increases. Since the number of bidirected pairs in \(\pi\) is at most |N| it follows that at most |N| swaps occur. \(\hfill\square\)

4.2 Ternary preferences

A natural question is whether the polynomial-time algorithm described in the proof of Theorem 4.3 can be extended to the setting in which preferences are ternary, i.e. \(v_{\alpha _i}(\alpha _j) \in \{ 0, 1, 2 \}\). We show that, assuming \(\textsf {P}\ne \textsf {NP}\), this is not the case. Specifically, we show that a given ASHG may not contain a j-envy-free partition into triples and the associated decision problem is \(\textsf {NP}\)-complete, even when preferences are ternary.

We present a polynomial-time reduction from a special case of Directed Triangle Packing (DTC, Problem 4.4).

Problem 4.4

Directed Triangle Packing (DTC)

      Input: a simple directed graph \(G=(W, A)\) where \(W=\{ w_1, w_2, \dots , w_{3q} \}\)

      for some integer q

      Question: Can the vertices of G be partitioned into q disjoint sets \(X=\)

      \(\{X_1, X_2, \dots , X_q\}\), each set containing exactly three vertices, such that each

      \(X_p=\{ w_i,w_j,w_k \}\) in X is a directed 3-cycle, i.e. \(( w_i,w_j ) \in\)

      A, \(( w_j, w_k ) \in A\), and \(( w_k, w_i ) \in A\)?

As shown by Cechlárová, Fleiner, and Manlove, DTC is \(\textsf {NP}\)-complete even when G is antisymmetric [36] (i.e. it contains no bidirectional arcs). We first describe the reduction, from this special case of DTC, and then provide some intuition with respect to its design.

The reduction, illustrated in Fig. 5, is as follows. Suppose \(G=(W, A)\) is an arbitrary instance of DTC. We shall construct an ASHG (NV). Unless otherwise specified, assume that \(v_{\alpha _i}(\alpha _j)=0\) for any \(\alpha _i\) and \(\alpha _j\) in N. To simplify the description of the reduction, in this section we write \(i \oplus y\) meaning \(((i + y - 1) \bmod 5) + 1\).

First construct a set of five agents \(H = \{ h_1, h_2, h_3, h_4, h_5 \}\). For each i where \(1\le i \le 5\) let \(v_{h_i}(h_{i \oplus 1}) = v_{h_{i \oplus 1}}(h_i) = 1\), \(v_{h_i}(h_{i \oplus 3}) = 1\), and \(v_{h_i}(h_{i \oplus 2}) = 2\). Next, construct a set \(L = \{ l_1, l_2, l_3, l_4 \}\) of four agents. Let \(v_{l_1}(l_2) = v_{l_2}(l_1) = v_{l_3}(l_4) = v_{l_4}(l_3) = 2\) and \(v_{l_1}(l_3) = v_{l_1}(l_4) = v_{l_2}(l_3) = v_{l_2}(l_4) = v_{l_3}(l_1) = v_{l_3}(l_2) = v_{l_4}(l_1) = v_{l_4}(l_2) = 1\). Next, construct a set \(C = \{ c_1, c_2, \dots , c_{3q} \}\) of 3q agents. For each i where \(1\le i \le 3q\), let \(v_{c_i}(l_3) = v_{l_3}(c_i) = v_{l_4}(c_i) = 1\) and \(v_{c_i}(l_4) = 2\). For each i and j where \(1\le i, j \le 3q\), let \(v_{c_i}(c_j) = 2\) if \(( w_i, w_j ) \in A\) otherwise 1. The construction of (NV) is now complete. Note that the structure of the valuations among the agents in C now reflects the directed graph G.

We remark that the design of H is derived from a particular instance that contains no j-envy-free partition into triples. To construct this instance, delete every agent in N other than the agents in H and \(l_1\). The accompanying proof, which shows that this instance contains no j-envy-free partition into triples, can be derived straightforwardly from the proof of Lemma 4.7, which appears later in this section.

It is straightforward to show that the reduction runs in polynomial time. To prove that the reduction is correct we show that the ASHG (NV) contains a j-envy-free partition into triples if and only if the DTC instance G contains a directed triangle cover.

Fig. 5
figure 5

The reduction from DTC to the problem of deciding if a given ASHG with ternary preferences contains a j-envy-free partition into triples

We first show that if the DTC instance G contains a directed triangle cover then the ASHG (NV) contains a j-envy-free partition into triples.

Lemma 4.5

If G contains a directed triangle cover then (NV) contains a j-envy-free partition into triples.

Proof

Suppose G contains a directed triangle cover \(X = \{ X_1, X_2, \dots , X_q \}\). We shall construct a partition into triples \(\pi\) that is j-envy-free. First, add \(\{ h_1, h_2, h_3 \}\), \(\{ h_4, l_1, l_2 \}\), and \(\{ h_5, l_3, l_4 \}\) to \(\pi\). Next, for each directed 3-cycle \(X_p = \{ w_i, w_j, w_k \}\) in X, add \(\{ c_i, c_j, c_k \}\) to \(\pi\).

Suppose for a contradiction that some agent \(\alpha _j\) exists where \(\alpha _j\) has j-envy for some other agent \(\alpha _{k_1}\) where \(\pi (\alpha _{k_1}) = \{ \alpha _{k_1}, \alpha _{k_2}, \alpha _{k_3} \}\). Since \(N = H \cup L \cup C\) it must be that either \(\alpha _{k_1} \in H\), \(\alpha _{k_1} \in L\), or \(\alpha _{k_1} \in C\). We show that each case leads to a contradiction. It then follows that no such \(\alpha _j\) exists and thus that \(\pi\) is j-envy-free.

  • Suppose \(\alpha _{k_1} \in H\). By the construction of \(\pi\) there are two possibilities: either \(\alpha _{k_1} \in \{ h_1, h_2, h_3 \}\) or \(\alpha _{k_1} \in \{ h_4, h_5 \}\).

    • Suppose firstly that \(\alpha _{k_1} \in \{ h_4, h_5 \}\). By the construction of \(\pi\) either \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_1, l_2 \}\) or \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_3, l_4 \}\). Note that \(u_{l_1}(\pi ) = u_{l_2}(\pi ) = u_{l_3}(\pi ) = u_{l_4}(\pi ) = 2\). Since \(u_{l_1}(\{ l_3, l_4 \}) = 2\) and \(u_{l_2}(\{ l_3, l_4 \}) = 2\), neither \(l_1\) nor \(l_2\) has j-envy for \(\alpha _{k_1}\), so \(\alpha _j \notin \{ l_1, l_2 \}\). Similarly, since \(u_{l_3}(\{ l_1, l_2 \}) = 2\) and \(u_{l_4}(\{ l_1, l_2 \}) = 2\) neither \(l_3\) nor \(l_4\) has j-envy for \(\alpha _{k_1}\), so \(\alpha _j \notin \{ l_3, l_4 \}\). Since \(u_{c_i}(\pi ) = 3\), \(u_{c_i}(\{ l_1, l_2 \}) = 0\), and \(u_{c_i}(\{ l_1, l_2 \}) = 2\) for any i where \(1\le i \le 3q\), it must be no agent in C has j-envy for \(\alpha _{k_1}\), so \(\alpha _j \notin C\). It remains that \(\alpha _{j} \in H\). Since this implies \(v_{l_1}(\alpha _j) = v_{l_2}(\alpha _j) = v_{l_3}(\alpha _j) = v_{l_4}(\alpha _j) = 0\) it follows that \(\alpha _j\) does not have j-envy for \(\alpha _{k_1}\) and thus that \(\alpha _{k_1} \notin \{ h_4, h_5 \}\).

    • Suppose then that \(\alpha _{k_1} \in \{ h_1, h_2, h_3 \}\). Since \(\alpha _j\) has j-envy for \(\alpha _{k_1}\) it must be that \(v_{\alpha _j}(\alpha _{k_2}) \ge 1\) so it follows that \(\alpha _j \in \{ h_4, h_5 \}\). If \(\alpha _{k_1} = h_1\) and \(\alpha _j = h_4\) then we reach a contradiction since \(h_4\) has j-envy for \(h_1\) but \(v_{h_3}(h_1) = 1 = v_{h_3}(h_4)\). Similarly, if \(\alpha _{k_1} = h_1\) and \(\alpha _j = h_5\) then we reach a contradiction since \(v_{h_2}(h_1) = 1 = v_{h_2}(h_5)\). If \(\alpha _{k_1} = h_2\) or \(\alpha _{k_1} = h_3\) then we also reach a contradiction since \(v_{h_1}(h_4) = v_{h_1}(h_5) = 1 = v_{h_1}(h_2) < 2 = v_{h_1}(h_3)\).

  • Suppose \(\alpha _{k_1} \in C\). By the construction of \(\pi\) it must be that \(\alpha _{k_2} \in C\) and \(\alpha _{k_3} \in C\) so we label \(\alpha _{k_1} = c_{i_1}\), \(\alpha _{k_2} = c_{i_2}\), and \(\alpha _{k_3} = c_{i_3}\). By the construction of (NV) in the reduction it follows that \(v_{c_{i_2}}(c_{i_1}) \ge 1\) and \(v_{c_{i_3}}(c_{i_1}) \ge 1\). Since \(\alpha _j\) has j-envy for \(c_{i_1}\) it follows then that \(v_{c_{i_2}}(\alpha _j) = 2\) and \(v_{c_{i_3}}(\alpha _j) = 2\). By the construction of the instance there are two possibilities: either \(\alpha _j = l_4\) or \(\alpha _j \in C\). If \(\alpha _j = l_4\) then \(u_{l_4}(\{ c_{i_2}, c_{i_3} \}) = 2\) which is a contradiction since by assumption \(l_4\) has j-envy for \(c_{i_1}\) but \(u_{l_4}(\pi ) = 2\). If \(\alpha _j \in C\) then label \(\alpha _j = c_{i_4}\). Since \(v_{c_{i_2}}(c_{i_4}) = 2\) and \(v_{c_{i_3}}(c_{i_4}) = 2\), by the construction of C it must be that \(( w_{i_2}, w_{i_4} ) \in A\) and \(( w_{i_3}, w_{i_4} ) \in A\), where the vertices \(w_{i_2}, w_{i_3}, w_{i_4}\) are the vertices in W that correspond respectively to the agents \(c_{i_2}, c_{i_3}, c_{i_4}\) in C. Since G is antisymmetric, it follows that \(( w_{i_4}, w_{i_2} ) \notin A\) and \(( w_{i_4}, w_{i_3} ) \notin A\) so it must be that \(v_{c_{i_4}}(c_{i_2}) = v_{c_{i_4}}(c_{i_3}) = 1\). This is also a contradiction since by assumption \(c_{i_4}\) has j-envy for \(c_{i_1}\) but \(u_{c_{i_4}}(\{ c_{i_2}, c_{i_3} \}) = 2\) and by the construction of \(\pi\) it must be that \(u_{c_{i_4}}(\pi ) = 3\).

  • Suppose \(\alpha _{k_1} \in L\). It must be that \(\alpha _{k_1} = l_{i_1}\), \(\alpha _{k_2} = l_{i_2}\), and \(\alpha _{k_3} = h_{i_3}\), where \(1\le i_1, i_2 \le 4\) and \(i_3 \in \{ 4, 5 \}\). If \(\alpha _j \in H\) then it must be that \(v_{l_{i_2}}(\alpha _j) = 0\) which contradicts the supposition that \(\alpha _j\) has j-envy for \(l_{i_1}\). Otherwise, if \(\alpha _j \notin H\) then \(v_{h_{i_3}}(\alpha _j) = 0\), which also contradicts the supposition that \(\alpha _j\) has j-envy for \(l_{i_1}\). \(\hfill\square\)

We now show that if the ASHG (NV) contains a j-envy-free partition into triples then the DTC instance G contains a directed triangle cover. Recall that for any set of agents S, \(\sigma (S, \pi )\) is the number of triples in \(\pi\) that each contains at least one agent in S.

Lemma 4.6

If (NV) contains a j-envy-free partition into triples \(\pi\) then \(\sigma (H, \pi ) \ge 3\).

Proof

Since \(|H|=5\) it must be that \(\sigma (H, \pi ) \ge 2\). Suppose for a contradiction that \(\sigma (H, \pi ) = 2\). It must be that one triple in \(\pi\) contains three agents in H and one triple in \(\pi\) contains two agents in H. Suppose the former triple is \(\{ h_{i_1}, h_{i_2}, h_{i_3} \}\) and the latter triple is \(\{ h_{i_4}, h_{i_5}, \alpha _j \}\), where \(1\le i_1, i_2, \dots , i_5 \le 5\) and \(\alpha _j \in N \setminus H\). There are five symmetries in H and \(\left( {\begin{array}{c}5\\ 2\end{array}}\right) =10\) possible assignments of \(\{ h_{i_4}, h_{i_5} \}\) to two agents in H, so we need only consider the two assignments \(i_4 = 1\), \(i_5 = 2\) and \(i_4 = 1\), \(i_5 = 3\), which are not symmetric. If \(i_4 = 1\) and \(i_5 = 2\) then it remains that \(\{ i_1, i_2, i_3 \} = \{ 3, 4, 5 \}\). In this case, \(h_5\) has j-envy for \(\alpha _j\) since \(u_{h_5}(\pi ) = 2 < 3 \le u_{h_5}(\{ h_1, h_2 \})\), \(v_{h_1}(\alpha _j) = 0 < 1 = v_{h_1}(h_5)\), and \(v_{h_2}(\alpha _j) = 0 < 1 = v_{h_2}(h_5)\). If \(i_4 = 1\) and \(i_5 = 3\) then it remains that \(\{ i_1, i_2, i_3 \} = \{ 2, 4, 5 \}\). In this case, \(h_4\) has j-envy for \(\alpha _j\) since \(u_{h_4}(\pi ) = 2 < 3 \le u_{h_4}(\{ h_1, h_3 \})\), \(v_{h_1}(\alpha _j) = 0 < 1 = v_{h_1}(h_4)\), and \(v_{h_3}(\alpha _j) = 0 < 1 = v_{h_3}(h_4)\). \(\hfill\square\)

Lemma 4.7

If (NV) contains a j-envy-free partition into triples \(\pi\) then at least two triples in \(\pi\) each contains exactly one agent in H.

Proof

By Lemma 4.6, \(\sigma (H, \pi ) \ge 3\). If, contrary to the lemma statement, at most one triple in \(\pi\) contains exactly one agent in H then it must be that two triples in \(\pi\) each contains two agents in H and one triple in \(\pi\) contains exactly one agent in H. Suppose one of the two former triples is \(\{ h_{i_1}, h_{i_2}, \alpha _{j_1} \}\) and the latter triple is \(\{ h_{i_3}, \alpha _{j_2}, \alpha _{j_3} \}\), where \(1\le i_1, i_2, i_3 \le 5\) and \(\alpha _{j_1}, \alpha _{j_2}, \alpha _{j_3} \in N {\setminus } H\). By the construction of the instance it must be that \(v_{h_{i_1}}(\alpha _{j_1}) = v_{h_{i_2}}(\alpha _{j_1}) = 0\), \(v_{h_{i_1}}(h_{i_3}) \ge 1\) and \(v_{h_{i_2}}(h_{i_3}) \ge 1\). It follows that \(h_{i_3}\) has j-envy for \(\alpha _{j_1}\) since \(u_{h_{i_3}}(\pi ) = 0 < 2 \le u_{h_{i_3}}(\{ h_{i_1}, h_{i_2} \})\), \(v_{h_{i_1}}(\alpha _j) = 0 < 1 \le v_{h_{i_1}}(h_{i_3})\), and \(v_{h_{i_2}}(\alpha _j) = 0 < 1 \le v_{h_{i_2}}(h_{i_3})\). This contradicts the supposition that \(\pi\) is j-envy-free. \(\hfill\square\)

We have shown in Lemma 4.7 that if (NV) contains a j-envy-free partition into triples \(\pi\) then at least two triples in \(\pi\) each contains exactly one agent in H. Suppose \(t_{\beta }\) and \(t_{\gamma }\) are two such triples where \(t_{\beta } = \{ h_{a_1}, \alpha _{b_1}, \alpha _{b_2} \}\) and \(t_{\gamma } = \{ h_{a_2}, \alpha _{b_3}, \alpha _{b_4} \}\).

Lemma 4.8

If (NV) contains a j-envy-free partition into triples then \(\{ \alpha _{b_1},\alpha _{b_2}, \alpha _{b_3},\alpha _{b_4} \} = L\).

Proof

Suppose for a contradiction that \(\{ \alpha _{b_1}, \alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \} \ne L\).

By definition, \(\{ \alpha _{b_1}, \alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \} \cap H = \varnothing\) and \(\{ \alpha _{b_1}, \alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \} \ne L\) it must be that at least one agent in \(\{ \alpha _{b_1}, \alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \}\) belongs to C. Assume without loss of generality that \(\alpha _{b_1} \in C\).

Note that by construction of the instance, the valuation of any agent not in H for any other agent not in H is at least 1.

Since \(\alpha _{b_2} \notin H\), it must be that \(u_{\alpha _{b_2}}(\pi ) = v_{\alpha _{b_2}}(\alpha _{b_1})\). By the design of the instance, since \(\alpha _{b_2} \notin H\) and \(\alpha _{b_1} \notin H\) it must be that \(v_{\alpha _{b_2}}(\alpha _{b_1}) \in \{ 1, 2 \}\). We consider each possibility of \(u_{\alpha _{b_2}}(\pi ) = v_{\alpha _{b_2}}(\alpha _{b_1})\).

Firstly, suppose \(u_{\alpha _{b_2}}(\pi ) = 1\). As noted earlier in this proof, since \(\alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \in N {\setminus } H\) it must be that \(v_{\alpha _{b_2}}(\alpha _{b_3}) \ge 1\) and \(v_{\alpha _{b_2}}(\alpha _{b_4}) \ge 1\). It follows that \(\alpha _{b_2}\) has j-envy for \(h_{a_2}\), since \(u_{\alpha _{b_2}}(\pi ) = 1 < 2 \le u_{\alpha _{b_2}}(\{ \alpha _{b_3}, \alpha _{b_4} \})\), \(v_{\alpha _{b_3}}(h_{a_2}) = 0 < 1 \le v_{\alpha _{b_3}}(\alpha _{b_2})\), and \(v_{\alpha _{b_4}}(h_{a_2}) = 0 < 1 \le v_{\alpha _{b_4}}(\alpha _{b_2})\). This contradicts the supposition that \(\pi\) is j-envy-free.

Suppose then that \(u_{\alpha _{b_2}}(\pi ) = 2\), so \(v_{\alpha _{b_2}}(\alpha _{b_1}) = 2\). Since \(\alpha _{b_1} \in C\) by assumption, by the design of the instance it must be that \(\alpha _{b_2} \in C\). For the remainder of this lemma only, label \(\alpha _{b_1} = c_{i_1}\) and \(\alpha _{b_2} = c_{i_2}\). Since \(v_{c_{i_2}}(c_{i_1}) = 2\) it follows that \(( w_{i_2}, w_{i_1} ) \in A\). Since G is antisymmetric it must be that \(( w_{i_1}, w_{i_2} ) \notin A\) and thus that \(v_{c_{i_1}}(c_{i_2}) = 1\). Since \(\pi (c_{i_1}) = \{ c_{i_1}, c_{i_2}, h_{a_1} \}\) it follows that \(u_{c_{i_1}}(\pi ) = v_{c_{i_1}}(c_{i_2}) = 1\). Now \(\alpha _{b_1}\) has j-envy for \(h_{a_2}\), since \(u_{\alpha _{b_1}}(\pi ) = 1 < 2 \le u_{\alpha _{b_1}}(\{ \alpha _{b_3}, \alpha _{b_4} \})\), \(v_{\alpha _{b_3}}(h_{a_2}) = 0 < 1 \le v_{\alpha _{b_3}}(\alpha _{b_1})\), and \(v_{\alpha _{b_4}}(h_{a_2}) = 0 < 1 \le v_{\alpha _{b_4}}(\alpha _{b_1})\). This contradicts the supposition that \(\pi\) is j-envy-free. \(\hfill\square\)

Lemma 4.9

If (NV) contains a j-envy-free partition into triples then \(\{ \{ \alpha _{b_1},\alpha _{b_2} \}, \{ \alpha _{b_3},\alpha _{b_4} \} \} = \{ \{ l_1,l_2 \}, \{ l_3,l_4 \} \}\).

Proof

By Lemma 4.8, \(\{ \alpha _{b_1}, \alpha _{b_2}, \alpha _{b_3}, \alpha _{b_4} \} = L\). There are now three possibilities: first that \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_3 \}, \{ l_2, l_4 \} \}\), second that \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_4 \}, \{ l_2, l_3 \} \}\), and third that \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_2 \}, \{ l_3, l_4 \} \}\).

First suppose \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_3 \}, \{ l_2, l_4 \} \}\). Without loss of generality assume that \(\alpha _{b_1} = l_1\). Now \(l_1\) has j-envy for \(h_{a_2}\) since \(u_{l_1}(\{ h_{a_1}, l_3 \}) = 1 < 3 = u_{l_1}(\{ l_2, l_4 \})\), \(v_{l_2}(h_{a_2}) = 0 < 2 = v_{l_2}(l_1)\), and \(v_{l_4}(h_{a_2}) = 0 < 1 = v_{l_4}(l_1)\).

Second suppose \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_4 \}, \{ l_2, l_3 \} \}\). Without loss of generality assume that \(\alpha _{b_1} = l_1\). As before, \(l_1\) has j-envy for \(h_{a_2}\) since \(u_{l_1}(\{ h_{a_1}, l_4 \}) = 1 < 3 = u_{l_1}(\{ l_2, l_3 \})\), \(v_{l_2}(h_{a_2}) = 0 < 2 = v_{l_2}(l_1)\), and \(v_{l_3}(h_{a_2}) = 0 < 1 = v_{l_3}(l_1)\).

It remains that \(\{ \{ \alpha _{b_1}, \alpha _{b_2} \}, \{ \alpha _{b_3}, \alpha _{b_4} \} \} = \{ \{ l_1, l_2 \}, \{ l_3, l_4 \} \}\). \(\hfill\square\)

By Lemma 4.9, either \(\{ \alpha _{b_1}, \alpha _{b_2} \} = \{ l_1, l_2 \}\) or \(\{ \alpha _{b_1}, \alpha _{b_2} \} = \{ l_3, l_4 \}\). Without loss of generality assume that \(\{ \alpha _{b_1}, \alpha _{b_2} \} = \{ l_3, l_4 \}\).

Lemma 4.10

If (NV) contains a j-envy-free partition into triples \(\pi\) then \(u_{c_i}(\pi ) \ge 3\) for each agent \(c_i\) in C.

Proof

Suppose to the contrary that some \(1\le i \le 3q\) exists where \(u_{c_i}(\pi ) < 3\). Then \(c_i\) has j-envy for \(h_{a_1}\) since \(u_{c_i}(\pi ) \le 2 < 3 = u_{c_i}(\{ l_3, l_4 \})\), \(v_{l_3}(h_{a_1}) = 0 < 1 = v_{l_3}(c_i)\), and \(v_{l_4}(h_{a_1}) = 0 < 1 = v_{l_4}(c_i)\). \(\hfill\square\)

Lemma 4.11

If (NV) contains a j-envy-free partition into triples \(\pi\) then G contains a directed triangle cover.

Proof

Suppose (NV) contains a j-envy-free partition into triples \(\pi\). Lemma 4.10 shows that \(u_{c_i}(\pi ) \ge 3\) for each agent \(c_i\) in C. By construction, it follows that \(\pi (c_i)\) contains two agents \(c_j, c_k\) such that \(v_{c_i}(c_j) \ge 1\) and \(v_{c_i}(c_k) = 2\). Hence \(c_k\) corresponds to a vertex \(w_k\) in W where \(( w_i, w_k ) \in A\) and, since G is antisymmetric, \(( w_k, w_i ) \notin A\). Since \(c_i\) was chosen arbitrarily it follows that \(\{ w_i, w_j, w_k \}\) is a directed 3-cycle in G. It follows thus that there are exactly q triples in \(\pi\) each containing three agents \(\{ c_i, c_j, c_k \}\) where the three corresponding vertices \(\{ w_i, w_j, w_k \}\) form a directed 3-cycle in G. From these triples a directed triangle cover X can be easily constructed. \(\hfill\square\)

We have now shown that the ASHG (NV) contains a j-envy-free partition into triples if and only if the DTC instance G contains a directed triangle cover. This shows that the reduction is correct.

Theorem 4.12

Deciding if a given ASHG contains a j-envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are ternary.

Proof

It is straightforward to show that this decision problem belongs to \(\textsf {NP}\), since for any two agents \(\alpha _i, \alpha _j \in N\) we can test if \(\alpha _i\) j-envies \(\alpha _j\) in constant time.

We have presented a polynomial-time reduction from a special case of DTC, which is \(\textsf {NP}\)-complete [36]. Given a directed antisymmetric graph G, the reduction constructs an ASHG with ternary preferences (NV). Together, Lemmas 4.5 and 4.11 show that (NV) contains a j-envy-free partition into triples if and only if G contains a directed triangle cover, and thus that this decision problem is \(\textsf {NP}\)-hard. \(\hfill\square\)

4.3 Non-binary and symmetric preferences

From Theorems 4.3 and 4.12, a natural question arises: is it the symmetry of agents’ preferences that guarantees the existence of a j-envy-free partition into triples?

In this section we show that this is not the case, and a j-envy-free partition into triples may not exist even when agents’ preferences are symmetric, and the associated existence problem is \(\textsf {NP}\)-complete. In fact, we show that this problem is \(\textsf {NP}\)-complete even when agents’ valuations are symmetric and between 0 and 6 inclusive. It remains open whether this result also applies to further restricted cases in which agents’ valuations are strictly less than 6. In particular, whether this result can be strengthened to the restricted case in which preferences are ternary and symmetric.

It seems tricky to design an ASHG in which preferences are non-binary and symmetric that does not contain a j-envy-free partition into triples. In fact, the authors were unable to do this by hand and instead relied on random search, in part inspired by a strategy used by Bullinger [37] in a similar endeavour. The search involved repeatedly generating candidate instances and testing, using an integer programming-based solution, whether any candidate did not contain a j-envy-free partition into triples. Certain assumptions were made in order to reduce the search space. For example, it was assumed that any such instance would contain at most 12 agents. It was also assumed that there would be a single agent for which any other agent has a valuation of 0. This assumption was inspired by the idea of an “undesired guest” [25] [38, Example 3]. It was also assumed that the core part of the instance would have a number of structural symmetries.

After the search identified an initial “no” instance, the authors were then able to simplify it further. In order to avoid repetition, we do not describe the final instance explicitly. Instead, we first describe the associated polynomial-time reduction and then how to construct the final instance from a gadget used in the reduction. The accompanying proof, which shows that this instance contains no j-envy-free partition into triples, can be derived straightforwardly from the proof of Lemma 4.15, which appears later in this section.

The polynomial-time reduction that we present is from Partition into Triangles (PIT, Problem 4.13). It is similar to the reduction we presented in Sect. 4.2 for the analogous problem involving ternary preferences that are not (necessarily) symmetric. In that section we reduced from Directed Triangle Packing (DTC) but here we reduce from PIT.

Problem 4.13

Partition Into Triangles (PIT)

      Input: a simple undirected graph \(G=(W, E)\) where \(|W|=3q\) for some

      integer q

      Question: Can the vertices of G be partitioned into q disjoint sets \(X=\)

      \(\{ X_1, X_2, \dots , X_q \}\), each set containing exactly three vertices, such that each

      \(X_p = \{ w_i, w_j, w_k \}\) where \(1\le p\le q\) is a triangle?

PIT is \(\textsf {NP}\)-complete [33, Theorem 3.7]. The reduction, illustrated in Fig. 6, is as follows. Suppose G is an arbitrary instance of PIT. We shall construct an ASHG (NV) that has symmetric preferences and maximum valuation 6. Since the valuations in (NV) will be symmetric, we shall usually specify valuations in one direction only. For example, instead of writing “let \(v_{\alpha _i}(\alpha _j)=v_{\alpha _j}(\alpha _i)=1\)” we write “let \(v_{\alpha _i}(\alpha _j)=1\)”. Unless otherwise specified, assume that \(v_{\alpha _i}(\alpha _j)=0\) for any \(\alpha _i, \alpha _j \in N\). To simplify the description of the reduction, in this section we write \(i \oplus y\) meaning \(((i + y - 2) \bmod 10) + 2\).

First, construct a set of eleven agents \(H = \{ h_1, h_2, \dots , h_{11} \}\). For each i where \(2\le i \le 11\) let \(v_{h_1}(h_i) = 2\). For each i where \(2\le i \le 11\), let:

  • \(v_{h_i}(h_{i \oplus 1}) = 4\) if i is even otherwise 5

  • \(v_{h_i}(h_{i \oplus 2}) = 6\) if i is even otherwise 3

  • \(v_{h_i}(h_{i \oplus 3}) = 1\)

  • \(v_{h_i}(h_{i \oplus 4}) = 1\)

  • \(v_{h_i}(h_{i \oplus 5}) = 3\).

Next, construct a set of four agents \(L = \{ l_1, l_2, l_3, l_4 \}\). Let \(v_{l_1}(l_2) = v_{l_3}(l_4) = 2\) and \(v_{l_1}(l_3) = v_{l_1}(l_4) = v_{l_2}(l_3) = v_{l_2}(l_4) = 1\).

Next, construct a set of 3q agents \(C = \{ c_1, c_2, \dots , c_{3q} \}\). Let \(v_{c_i}(l_r) = 3\) for each i and r where \(1\le i \le 3q\) and \(1\le r \le 4\). For each i and j where \(1\le i, j \le 3q\) let \(v_{c_i}(c_j) = 3\) if \(\{ w_i, w_j \} \in E\) otherwise 2. The construction of (NV) is now complete. Note that the structure of the valuations among the agents in C reflects the graph G.

We remark that the design of H is derived from a particular instance that contains no j-envy-free partition into triples. To construct this instance, delete every agent in N other than the agents in H and \(l_1\). The resulting instance thus contains valuations between 0 and 6 inclusive.

It is straightforward to show that the reduction runs in polynomial time. To prove that the reduction is correct we show that the ASHG (NV) contains a j-envy-free partition into triples if and only if the PIT instance G contains a partition into triangles.

Fig. 6
figure 6

The reduction from PIT to the problem of deciding if an ASHG with symmetric preferences contains a j-envy-free partition into triples. Valuation colour key: red—6, green—5, blue—4, black—3, purple—2, grey—1 (Color figure online)

We first show that if the PIT instance G contains a partition into triangles then the ASHG (NV) contains a j-envy-free partition into triples.

Lemma 4.14

If G contains a partition into triangles then (NV) contains a j-envy-free partition into triples.

Proof

Suppose G contains a partition into triangles \(X = \{ X_1, X_2, \dots , X_q \}\). We shall construct a partition into triples \(\pi\) that is j-envy-free. First, add \(\{ h_2, h_{10}, h_{11} \}\), \(\{ h_5, h_6, h_8 \}\), \(\{ h_1, h_9, h_4 \}\), \(\{ h_3, l_1, l_2 \}\) and \(\{ h_7, l_3, l_4 \}\) to \(\pi\). Next, for each triangle \(X_p = \{ w_i, w_j, w_k \}\) in X, add \(\{ c_i, c_j, c_k \}\) to \(\pi\).

Suppose for a contradiction that some agent \(\alpha _j\) exists where \(\alpha _j\) has j-envy for some other agent \(\alpha _{k_1}\) where \(\pi (\alpha _{k_1}) = \{ \alpha _{k_1}, \alpha _{k_2}, \alpha _{k_3} \}\). Since \(N = H \cup L \cup C\) it must be that either \(\alpha _{k_1} \in H\), \(\alpha _{k_1} \in L\), or \(\alpha _{k_1} \in C\). We show that each case leads to a contradiction. It follows that no such \(\alpha _j\) exists and thus that \(\pi\) is j-envy-free.

  • Suppose \(\alpha _{k_1} \in H\). Either \(\alpha _{k_1} \in \{ h_3, h_7 \}\) or \(\alpha _{k_1} \in H {\setminus } \{ h_3, h_7 \}\).

    • Suppose \(\alpha _{k_1} \in \{ h_3, h_7 \}\). Then it must be that either \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_1, l_2 \}\) or \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_3, l_4 \}\). Suppose firstly that \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_1, l_2 \}\). We can see immediately that \(\alpha _j \notin H\) since otherwise \(u_{\alpha _j}(\{ l_1, l_2 \}) = 0\). It must also be that \(\alpha _j \notin C\), since \(u_{c_{a}}(\{ l_1, l_2 \}) = 6 = u_{c_a}(\pi )\) for any \(c_a\) in C. Similarly, \(u_{l_3}(\{ l_1, l_2 \}) = 2 = u_{l_3}(\pi )\) and \(u_{l_4}(\{ l_1, l_2 \}) = 2 = u_{l_4}(\pi )\) so \(\alpha _j \ne l_3\) and \(\alpha _j \ne l_4\). This shows \(\alpha _j \notin L\). We have shown that \(\alpha _j \notin H\), \(\alpha _j \notin C\), and \(\alpha _j \notin L\), which is a contradiction. The proof for the case in which \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ l_3, l_4 \}\) is symmetric and also leads to a contradiction.

    • Suppose \(\alpha _{k_1} \in H\setminus \{ h_3, h_7 \}\). If \(\alpha _{k_1} = h_1\) then \(\{ \alpha _{k_2}, \alpha _{k_3} \} = \{ h_4, h_9 \}\) so it must be that \(v_{h_4}(\alpha _j) > 2 = v_{h_4}(h_1)\) and \(v_{h_9}(\alpha _j) > 2 = v_{h_9}(h_1)\), which is impossible by the design of H. The proof for every other assignment of \(\alpha _{k_1}\) is similar: if \(\alpha _{k_1} = h_2\) then \(v_{h_{11}}(\alpha _j) > 5\), which is impossible. If \(\alpha _{k_1} = h_4\) then \(v_{h_1}(\alpha _j) > 2\), which is impossible. If \(\alpha _{k_1} = h_5\) then \(v_{h_6}(\alpha _j) > 5\) and \(v_{h_8}(\alpha _j) > 1\), which is impossible. If \(\alpha _{k_1} = h_6\) then \(v_{h_8}(\alpha _j) > 6\), which is impossible. If \(\alpha _{k_1} = h_8\) then \(v_{h_6}(\alpha _j) > 6\), which is impossible. If \(\alpha _{k_1} = h_9\) then \(v_{h_1}(\alpha _j) > 2\), which is impossible. If \(\alpha _{k_1} = h_{10}\) then \(v_{h_2}(\alpha _j) > 6\), which is impossible. If \(\alpha _{k_1} = h_{11}\) then \(v_{h_2}(\alpha _j) > 5\) and \(v_{h_{10}}(\alpha _j) > 4\), which is impossible.

  • Suppose \(\alpha _{k_1} \in C\). By construction, it must be that \(\alpha _{k_1} = c_{i_1}\), \(\alpha _{k_2} = c_{i_2}\), and \(\alpha _{k_3} = c_{i_3}\) where \(\{ c_{i_1}, c_{i_2}, c_{i_3} \} \subseteq C\), where the corresponding (vert)ices \(\{ w_{i_1}, w_{i_2}, w_{i_3} \}\) in G are a triangle. It follows that \(v_{c_{i_2}}(c_{i_1}) = 3\). By assumption, \(\alpha _j\) has j-envy for \(c_{i_1}\) so it must be that \(v_{c_{i_2}}(\alpha _j) > v_{c_{i_2}}(c_{i_1}) = 3\), which is impossible by the design of C.

  • Suppose \(\alpha _{k_1} \in L\). It must be that \(\alpha _{k_1} = l_{i_1}\) for some integer \(i_1\) where \(1\le i_1 \le 4\), \(\alpha _{k_2} = l_{i_2}\) for some integer \(i_2\) where \(1\le i_2 \le 4\) and \(\alpha _{k_3} = h_{i_3}\) where \(i_3 \in \{ 3, 7 \}\). If \(\alpha _j \in H\) then \(v_{l_{i_2}}(\alpha _j) = 0\) which contradicts the supposition that \(\alpha _j\) has j-envy for \(l_{i_1}\). Otherwise, if \(\alpha _j \notin H\) then \(v_{h_{i_3}}(\alpha _j) = 0\), which also contradicts the supposition that \(\alpha _j\) has j-envy for \(l_{i_1}\). \(\hfill\square\)

The next step is to show that if the ASHG (NV) contains a j-envy-free partition into triples then the PIT instance G contains a partition into triangles. The full proof involves an extensive case analysis so is deferred to Appendix B.

Lemma 4.15

If (NV) contains a j-envy-free partition into triples then G contains a partition into triangles.

Proof sketch

First, we assume that (NV) contains a j-envy-free partition into triples \(\pi\). Next, we consider H and show that there is essentially only one possible configuration of the triples in \(\pi\) that contain agents in H. Specifically, we show that some triple in \(\pi\) comprises \(l_1\), \(l_2\), and some agent in H, which we call \(h_{a_1}\). It follows that \(u_{c_i}(\pi ) = 6\) for each i where \(1\le i \le 3q\), since otherwise there exists some agent \(c_i\) in C with j-envy for \(h_{a_1}\). It is then straightforward to show that there are exactly q triples in \(\pi\), each of which contains three agents in C, that correspond to a triangle in G. These q triples reveal a partition into triangles in G. \(\hfill\square\)

Theorem 4.16

Deciding if a given ASHG contains a j-envy-free partition into triples is \(\textsf {NP}\)-complete even when preferences are symmetric and each agent’s valuations are between 0 and 6.

Proof

It is straightforward to show that this decision problem belongs to \(\textsf {NP}\), since for any two agents \(\alpha _i\) and \(\alpha _j\) in N we can test if \(\alpha _i\) j-envies \(\alpha _j\) in constant time.

We have presented a polynomial-time reduction from PIT, which is \(\textsf {NP}\)-complete [33]. Given an undirected graph G, the reduction constructs an ASHG with symmetric preferences (NV) in which each agent’s valuations are between 0 and 6 inclusive. Together, Lemmas 4.14 and 4.15 show that (NV) contains a j-envy-free partition into triples if and only if G contains a partition into triangles, and thus that this decision problem is \(\textsf {NP}\)-hard. \(\hfill\square\)

5 Conclusion

In this paper we considered three successively weaker solution concepts: envy-freeness, weakly justified envy-freeness, and justified envy-freeness, and studied the existence of partitions into triples that satisfy each concept together with associated search problems. We imposed various restrictions on the agents’ preferences and presented a complete complexity classification in terms of these restrictions.

Our polynomial-time algorithms may have practical applications. For example, our algorithm for justified envy-freeness could be applied to a real-life situation involving “friends” and “neutrals” [39]. Our algorithms for envy-freeness and wj-envy-freeness can only be applied to settings in which the agents’ preferences are heavily restricted. While such a restriction may not necessarily be realistic in practice, in theory characterising the frontier between solvability and \(\textsf {NP}\)-completeness is a first step.

The scope for future work is wide. An immediate open question is whether Theorem 4.16 can be strengthened to ASHGs with ternary and symmetric preferences. As we remarked in Sect. 4.3, it seems tricky to design an ASHG with symmetric preferences in which there is no j-envy-free partition into triples. We discussed the random search technique used to discover such an instance, which was partly inspired by previous work [37]. Although this technique was effective, it seems hard to provide intuition as to why the discovered instance contains no j-envy-free partition into triples. It is also still unknown whether any simpler instance exists, for example with fewer than 12 agents.

Another immediate question is the extent to which our results generalise to other restrictions on coalition size, for example if coalitions must have size k, for some fixed k where \(k\ge 3\). We conjecture that all of our \(\textsf {NP}\)-hardness reductions can be generalised to this setting.

Studying more general solution concepts, such as envy-free up to r (EF-r) [28], may lead to more interesting efficient algorithms. It is also possible to define a new type of envy between j-envy and wj-envy such that \(\alpha _i\) has r-j-envy for \(\alpha _j\) if \(\alpha _i\) has weakly justified envy for \(\alpha _j\) and at least r agents in \(\pi (\alpha _j)\) prefer \(\alpha _i\) to \(\alpha _j\). In a model in which coalitions must have size k, k-j-envy coalesces with j-envy.

Similarly, it could also be interesting to investigate ordinal preferences, for example considering complete, \({\mathscr {B}}\)-, \({\mathscr {W}}\)-, or lexicographic preferences [40,41,42]. We conjecture that in a hedonic game model with \({\mathscr {B}}\)-preferences [40], an envy-free partition may not exist, and the associated existence problem is solvable in polynomial time.

Another possibility is to identify other restrictions on the agents’ valuations in which an envy-free, wj-envy-free or j-envy-free partition into triples can be found in polynomial time. The gadgets used in our reductions are highly regular and it might be that there exist interesting classes of instances that must contain an envy-free, wj-envy-free, or j-envy-free partition into triples. Alternatively, we could study these problems from the perspective of parameterised complexity. For example, in the case of binary and symmetric preferences, one could consider the tree-width [43] of the underlying graph.

It could also be interesting to estimate the probability that a randomly chosen ASHG contains an envy-free, wj-envy-free, or j-envy-free partition into triples, or to estimate the same probability in a random ASHG with binary or ternary preferences. Our complexity results indicate that, among instances with binary and symmetric preferences and maximum degree 2, the set of ASHGs that contain a j-envy-free partition into triples (i.e. all instances) is larger than the set of ASHGs that contain a wj-envy-free partition into triples, which is in turn larger than the set of ASHGs that contain an envy-free partition into triples. We conjecture that, in general, the probability that a given ASHG contains an envy-free partition into triples is smaller than the probability that it contains a wj-envy-free partition into triples, which is in turn smaller than the probability that it contains a j-envy-free partition into triples. In this direction, it might be possible to apply probabilistic techniques from graph theory, such as the Erdős-Rényi model of a random graph. Of course, the probabilistic events in which agents have envy for other agents are not independent, which complicates the analysis. Alternatively, an empirical approach might be informative.