33
UPC Departament de Llenguatges i Sistemes Informatics UNIVERSITAT POLITECNICA DE CATALUNYA Encoding Problems into Propositional Logic Javier Larrosa Albert Oliveras Enric Rodr ´ ıguez-Carbonell Problem Solving and Constraint Programming Sessions 4 and 5 Encoding Problems into Propositional Logic – p. 1

Encoding Problems into Propositional Logic

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Encoding Problems into Propositional Logic

Javier Larrosa

Albert OliverasEnric Rodrıguez-Carbonell

Problem Solving and Constraint Programming

Sessions 4 and 5

Encoding Problems into Propositional Logic – p. 1

Page 2: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 1 - No cheating exam distribution

According to the regulations in a given university, three days beforean exam takes place the professor is notified where each studentwill be sitting in the exam room.

Once the professor receives this information, he produces a list L ofpairs of students that are sitting too close to each other and hence,could easily cheat.

Assuming the professor only wants to produce E different exams,and there are S students, he wants to know whether there is a wayof distributing exams such that no two students sitting close to eachother get the same exam.

Write a propositional formula F such that

F is satisfiable iff such a distribution exists

from a model of F an exam distribution can be easily extracted

Encoding Problems into Propositional Logic – p. 2

Page 3: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 1 - No cheating exam distribution

VOCABULARY: for 1≤ i ≤ S and 1≤ j ≤ E ,pi, j ≈ i-th student receives exam j

CONSTRAINTS:

Each student receives exactly one exam:

Each student receives at least one exam:

Each student receives at most one exam:

Two students sitting next to each other get different exams:

Encoding Problems into Propositional Logic – p. 3

Page 4: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 1 - No cheating exam distribution

VOCABULARY: for 1≤ i ≤ S and 1≤ j ≤ E ,pi, j ≈ i-th student receives exam j

CONSTRAINTS:

Each student receives exactly one exam:

Each student receives at least one exam:

∀i with 1≤ i ≤ S one clause pi,1∨ pi,2∨ . . .∨ pi,E

Each student receives at most one exam:

Two students sitting next to each other get different exams:

Encoding Problems into Propositional Logic – p. 3

Page 5: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 1 - No cheating exam distribution

VOCABULARY: for 1≤ i ≤ S and 1≤ j ≤ E ,pi, j ≈ i-th student receives exam j

CONSTRAINTS:

Each student receives exactly one exam:

Each student receives at least one exam:

∀i with 1≤ i ≤ S one clause pi,1∨ pi,2∨ . . .∨ pi,E

Each student receives at most one exam:

∀i, j, j ′ with 1≤ i ≤ S and 1≤ j < j ′ ≤ Eone clause ¬pi, j ∨¬pi, j ′

Two students sitting next to each other get different exams:

Encoding Problems into Propositional Logic – p. 3

Page 6: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 1 - No cheating exam distribution

VOCABULARY: for 1≤ i ≤ S and 1≤ j ≤ E ,pi, j ≈ i-th student receives exam j

CONSTRAINTS:

Each student receives exactly one exam:

Each student receives at least one exam:

∀i with 1≤ i ≤ S one clause pi,1∨ pi,2∨ . . .∨ pi,E

Each student receives at most one exam:

∀i, j, j ′ with 1≤ i ≤ S and 1≤ j < j ′ ≤ Eone clause ¬pi, j ∨¬pi, j ′

Two students sitting next to each other get different exams:

∀i, i′, j with 1≤ i, i′ ≤ S , (i, i′) ∈ L and 1≤ j ≤ E

one clause ¬pi, j ∨¬pi′, j

Encoding Problems into Propositional Logic – p. 3

Page 7: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 2 - Scientific meeting

The Office for the Advance of Problem Solving Techniques wants toorganize a meeting with the most prominent researchers in the area.

In order to maximize the diversity of the approaches beingrepresented, no two attendants can be co-authors. For that purpose,

from the set of the N most brilliant researchers a list L of pairs ofco-authors is produced.

Assuming that, due to budget limitations, only K researchers willbe invited, we want to find out whether it is possible to celebrate ameeting satisfying these constraints.

Write a propositional formula F such that

F is satisfiable iff such a suitable choice of researchers exists

from a model of F the choice can be easily extracted

Encoding Problems into Propositional Logic – p. 4

Page 8: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 2 - Scientific meeting

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th invited researcher is researcher r j

CONSTRAINTS:

Each invited member is at least one prominent researcher:

Each invited member is at most one prominent researcher:

No researcher is invited twice:

No co-authors are invited:

Encoding Problems into Propositional Logic – p. 5

Page 9: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 2 - Scientific meeting

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th invited researcher is researcher r j

CONSTRAINTS:

Each invited member is at least one prominent researcher:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each invited member is at most one prominent researcher:

No researcher is invited twice:

No co-authors are invited:

Encoding Problems into Propositional Logic – p. 5

Page 10: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 2 - Scientific meeting

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th invited researcher is researcher r j

CONSTRAINTS:

Each invited member is at least one prominent researcher:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each invited member is at most one prominent researcher:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No researcher is invited twice:

No co-authors are invited:

Encoding Problems into Propositional Logic – p. 5

Page 11: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 2 - Scientific meeting

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th invited researcher is researcher r j

CONSTRAINTS:

Each invited member is at least one prominent researcher:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each invited member is at most one prominent researcher:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No researcher is invited twice:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤None clause ¬pi, j ∨¬pi′, j

No co-authors are invited:

Encoding Problems into Propositional Logic – p. 5

Page 12: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 2 - Scientific meeting

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th invited researcher is researcher r j

CONSTRAINTS:

Each invited member is at least one prominent researcher:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each invited member is at most one prominent researcher:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No researcher is invited twice:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤None clause ¬pi, j ∨¬pi′, j

No co-authors are invited:

∀i, i′, j, j ′ with 1≤ i, i′ ≤ K , i 6= i′, 1≤ j, j ′ ≤N and ( j, j ′) ∈ L

one clause ¬pi, j ∨¬pi′, j ′

Encoding Problems into Propositional Logic – p. 5

Page 13: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 3 - Gas stations

The government of Namibia wants to improve the distribution ofgas stations across the country. Currently, very long roads with nostations exist, which makes them dangerous for tourists.

It is known that the set of locations where some road starts or endsis reasonably small (size P ). Hence, the government thinks it isaffordable to place a gas station of the starting or ending point ofevery road.

Given a list L of all Namibian roads represented as pairs of

locations (start,end), and assuming that at mostK gas stations canbe constructed, we want to know whether a proper gas stationdistribution exists.

Write a propositional formula F such that

F is satisfiable iff such a distribution exists

from a model of F the distribution can be easily extracted

Encoding Problems into Propositional Logic – p. 6

Page 14: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 3 - Gas stations

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤ P ,pi, j ≈ i-th gas station is at j-th location

CONSTRAINTS:

No gas station can be at two different locations:

Each location at most has one gas station:

Each road has a gas station at its starting or ending point:

Encoding Problems into Propositional Logic – p. 7

Page 15: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 3 - Gas stations

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤ P ,pi, j ≈ i-th gas station is at j-th location

CONSTRAINTS:

No gas station can be at two different locations:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ Pone clause ¬pi, j ∨¬pi, j ′

Each location at most has one gas station:

Each road has a gas station at its starting or ending point:

Encoding Problems into Propositional Logic – p. 7

Page 16: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 3 - Gas stations

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤ P ,pi, j ≈ i-th gas station is at j-th location

CONSTRAINTS:

No gas station can be at two different locations:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ Pone clause ¬pi, j ∨¬pi, j ′

Each location at most has one gas station:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤ None clause ¬pi′, j ∨¬pi, j

Each road has a gas station at its starting or ending point:

Encoding Problems into Propositional Logic – p. 7

Page 17: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 3 - Gas stations

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤ P ,pi, j ≈ i-th gas station is at j-th location

CONSTRAINTS:

No gas station can be at two different locations:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ Pone clause ¬pi, j ∨¬pi, j ′

Each location at most has one gas station:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤ None clause ¬pi′, j ∨¬pi, j

Each road has a gas station at its starting or ending point:

For each road (locations, locatione) and ∀i with 1≤ i ≤ K

one clause(p1,s∨ p1,e)∨ (p2,s∨ p2,e)∨ . . . (pK ,s∨ pK ,e)

Encoding Problems into Propositional Logic – p. 7

Page 18: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 4 - Sabbatical year

After some years of hard work Mr. Hamilton decides to take asabbatical year to fulfill his dream. He plans to visit all his friendsaround the world using only direct flights and without goingthrough the same city twice except for the origin and end of the trip,which must coincide.

Knowing that his friends live in N different cities, and using the list

L of all direct flights ( pairs (origin,destination) ) between thesecities, Mr. Hamilton wants to decide whether his dream maybecome true.

Write a propositional formula F such that

F is satisfiable iff such a trip may be done

from a model of F the trip plan can be easily extracted

Encoding Problems into Propositional Logic – p. 8

Page 19: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 4 - Sabbatical year

VOCABULARY: for 1≤ i ≤N and 1≤ j ≤N ,pi, j ≈ i-th stop is at j-th city

CONSTRAINTS:

Each stop is in at least one city:

Each stop is in at most one city:

No city is visited in two stops:

Consecutive stops only between cities with direct flight:

Encoding Problems into Propositional Logic – p. 9

Page 20: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 4 - Sabbatical year

VOCABULARY: for 1≤ i ≤N and 1≤ j ≤N ,pi, j ≈ i-th stop is at j-th city

CONSTRAINTS:

Each stop is in at least one city:

∀i with 1≤ i ≤N one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each stop is in at most one city:

No city is visited in two stops:

Consecutive stops only between cities with direct flight:

Encoding Problems into Propositional Logic – p. 9

Page 21: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 4 - Sabbatical year

VOCABULARY: for 1≤ i ≤N and 1≤ j ≤N ,pi, j ≈ i-th stop is at j-th city

CONSTRAINTS:

Each stop is in at least one city:

∀i with 1≤ i ≤N one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each stop is in at most one city:

∀i, j, j ′ with 1≤ i ≤ N and 1≤ j < j ′ ≤N one clause¬pi, j ∨¬pi, j ′

No city is visited in two stops:

Consecutive stops only between cities with direct flight:

Encoding Problems into Propositional Logic – p. 9

Page 22: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 4 - Sabbatical year

VOCABULARY: for 1≤ i ≤N and 1≤ j ≤N ,pi, j ≈ i-th stop is at j-th city

CONSTRAINTS:

Each stop is in at least one city:

∀i with 1≤ i ≤N one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each stop is in at most one city:

∀i, j, j ′ with 1≤ i ≤ N and 1≤ j < j ′ ≤N one clause¬pi, j ∨¬pi, j ′

No city is visited in two stops:

∀i, i′, j with 1≤ i < i′ ≤ N and 1≤ j ≤N one clause ¬pi, j ∨¬pi′, j

Consecutive stops only between cities with direct flight:

Encoding Problems into Propositional Logic – p. 9

Page 23: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 4 - Sabbatical year

VOCABULARY: for 1≤ i ≤N and 1≤ j ≤N ,pi, j ≈ i-th stop is at j-th city

CONSTRAINTS:

Each stop is in at least one city:

∀i with 1≤ i ≤N one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each stop is in at most one city:

∀i, j, j ′ with 1≤ i ≤ N and 1≤ j < j ′ ≤N one clause¬pi, j ∨¬pi, j ′

No city is visited in two stops:

∀i, i′, j with 1≤ i < i′ ≤ N and 1≤ j ≤N one clause ¬pi, j ∨¬pi′, j

Consecutive stops only between cities with direct flight:

∀i, j, j ′ with 1≤ i <N , 1≤ j, j ′ ≤N and ( j, j ′) 6∈ L oneclause ¬pi, j ∨¬pi+1,j ′

∀ j, j ′ with 1≤ j, j ′ ≤N and ( j, j ′) 6∈ L one clause ¬pn, j ∨¬p1,j ′

Encoding Problems into Propositional Logic – p. 9

Page 24: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 5 - Winning team

For competing in the next Olympiads in Informatic, the Faculty ofInformatics of Barcelona (FIB) has to select K students to form thebest possible team.

After a long series of exams, the N best students have beenidentifed. Out of those ones, in order to obtain the best possiblework environment, the coaches decide to form a team where eachmember is friends with the rest of his/her team-mates.

For that purpose each student sgives a list L(s) of the friendshe/she has inside the group of the best students.

Write a propositional formula F such that

F is satisfiable iff such a team may be formed

from a model of F the team can be easily extracted

Encoding Problems into Propositional Logic – p. 10

Page 25: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

Each team member is at least one student:

Each team member is at most one student:

No student is two members:

All members are friends:

Encoding Problems into Propositional Logic – p. 11

Page 26: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

Each team member is at least one student:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each team member is at most one student:

No student is two members:

All members are friends:

Encoding Problems into Propositional Logic – p. 11

Page 27: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

Each team member is at least one student:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each team member is at most one student:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No student is two members:

All members are friends:

Encoding Problems into Propositional Logic – p. 11

Page 28: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

Each team member is at least one student:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each team member is at most one student:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No student is two members:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤None clause ¬pi, j ∨¬pi′, j

All members are friends:

Encoding Problems into Propositional Logic – p. 11

Page 29: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

Each team member is at least one student:

∀i with 1≤ i ≤ K one clause pi,1∨ pi,2∨ . . .∨ pi,N

Each team member is at most one student:

∀i, j, j ′ with 1≤ i ≤K and 1≤ j < j ′ ≤ None clause ¬pi, j ∨¬pi, j ′

No student is two members:

∀i, i′, j with 1≤ i < i′ ≤ K and 1≤ j ≤None clause ¬pi, j ∨¬pi′, j

All members are friends:

We should avoid combinatorial explosion

Encoding Problems into Propositional Logic – p. 11

Page 30: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 5 - Winning team

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,pi, j ≈ i-th member of the team is student sj

CONSTRAINTS:

All members are friends:

For 1≤ j ≤N create additional variables:c j ≈ student sj is chosen as part of the team

Related p’s and c′s:∀ j with 1≤ j ≤N add formula p1,j ∨ p2,j ∨ . . .∨ pK , j ↔ c j

All chosen students are friends:∀ j, j ′ with 1≤ j, j ′ ≤N and ( sj ′ 6∈ L(sj ) or sj 6∈ L(sj ′)) oneclause ¬c j ∨¬c j ′

Encoding Problems into Propositional Logic – p. 12

Page 31: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Example 6 - Winning team (bis)

For competing in the next Olympiads in Informatic, the Faculty ofInformatics of Barcelona (FIB) has to select K students to form thebest possible team.

After a long series of exams, the N best students have beenidentifed. Out of those ones, in order to obtain the best possiblework environment, the coaches decide to form a team where eachmember is friends with the rest of his/her team-mates and thatcontains the minimum amount of first-year students.

For that purpose each student sgives a list L(s) of the friendshe/she has inside the group of the best students, and also a listR offirst-year students is available.

Write a propositional formula F such that

F is satisfiable iff such a team may be formed

from a model of F the team can be easily extracted

Encoding Problems into Propositional Logic – p. 13

Page 32: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 6 - Winning team (bis)

VOCABULARY: for 1≤ i ≤K and 1≤ j ≤N ,

pi, j ≈ i-th member of the team is student sj

c j ≈ student sj is chosen as part of the team

CONSTRAINTS

All constraints from Solution 5

Minimize the number of first-year students

For this purpose we could add the constraint

CNF( ∑si∈R

ci ≤ B)

with B =N and decrease B while problem is satisfiable.

REMARK: there are methods to convert the cardinalityconstraint into a propositional CNF

Encoding Problems into Propositional Logic – p. 14

Page 33: Encoding Problems into Propositional Logic

UPC

Departament de Llenguatges i Sistemes Informatics

UNIVERSITAT POLITECNICA DE CATALUNYA‘

Solution 7 - Winning team (bis)

VOCABULARY: for 1≤ j ≤N ,

c j ≈ student sj is chosen as part of the team

CONSTRAINTS:

Exactly K students are chosen:

CNF(N

∑i=1

ci = K )

All members are friends:∀ j, j ′ with 1≤ j, j ′ ≤N and ( sj ′ 6∈ L(sj ) or sj 6∈ L(sj ′))one clause ¬c j ∨¬c j ′

Minimize the number of first-year studentsSame as before

This solution removes simmetries in Solution 6!!!!

Encoding Problems into Propositional Logic – p. 15