Assignment Chef icon Assignment Chef
All English tutorials

Programming lesson

Mastering Logic Programming with ASP: A Guide to CMT304's Patent Assignment Problem

Learn how to solve the CMT304 Programming Paradigms logic programming assignment using Answer Set Programming (ASP). This tutorial covers the guess-and-test methodology, constraint encoding, and optimization for the patent reviewer assignment problem.

CMT304 programming paradigms logic programming ASP answer set programming tutorial patent assignment problem guess and test methodology ASP constraints optimization programming paradigms assignment help ASP weak constraints workload balancing ASP expertise assignment logic AI combinatorial search ASP for scheduling CMT304 coursework solution logic programming examples ASP programming guide student programming help

Introduction to Logic Programming and ASP

Logic programming is a paradigm where programs are expressed as sets of logical statements. Answer Set Programming (ASP) is a modern logic programming language ideal for solving combinatorial search problems. In the CMT304 assignment, you must assign patent requests to referees subject to constraints on workload, expertise levels, and minimizing/maximizing certain categories. This tutorial will guide you through the core concepts and implementation strategies using ASP, focusing on the guess-and-test methodology.

Understanding the Patent Assignment Problem

Imagine a scenario similar to a popular AI-powered matchmaking app: referees (like users) declare their expertise for patent requests (like potential matches). The goal is to create assignments that satisfy multiple constraints. In the assignment, you are given a set of bid/3 facts: bid(ref, req, exp) where exp is one of Expert, Knowledgeable, Familiar, or Inexpert. Parameters n (number of referees per request), m (maximum workload difference), and k (max Familiar assignments per referee) are provided. Your output is a set of assign/2 facts.

Key Constraints

  • Exactly n referees per request: Each patent request must be assigned to exactly n referees.
  • Approximately equal workload: The number of assignments per referee should not differ by more than m.
  • Familiar limit: No referee reviews more than k Familiar submissions.
  • Optimization: Minimize Inexpert assignments and maximize Expert assignments.

Guess-and-Test Methodology in ASP

ASP follows a generate-and-test (or guess-and-test) approach. You first define a set of possible assignments (the guess), then impose constraints to eliminate invalid ones (the test). Finally, you use optimization statements to select the best solutions.

Step 1: Representing the Domain

Start by declaring the domain of referees and requests. Use referee/1 and request/1 predicates derived from the input bids:

referee(R) :- bid(R, _, _).
request(P) :- bid(_, P, _).

Step 2: Guessing Assignments

Use a choice rule to guess assignments. For each request, we need to choose exactly n referees. The following rule generates possible assignments:

{assign(R, P) : bid(R, P, _)} = N :- request(P), N = n.

This rule says: for each request P, the number of assigned referees R that have a bid for P must equal n. The n here is a constant parameter provided as input.

Step 3: Enforcing Workload Balance

To ensure workloads differ by at most m, compute the number of assignments per referee and constrain the difference:

workload(R, W) :- referee(R), W = #count{ P : assign(R, P) }.
:- workload(R1, W1), workload(R2, W2), |W1 - W2| > m.

The first rule calculates workload W for each referee. The second rule (constraint) rejects any solution where the absolute difference exceeds m.

Step 4: Limiting Familiar Assignments

Count the number of Familiar assignments per referee and enforce the limit k:

familiar_count(R, C) :- referee(R), C = #count{ P : assign(R, P), bid(R, P, Familiar) }.
:- familiar_count(R, C), C > k.

Step 5: Optimizing Expertise

Use weak constraints (optimization) to minimize Inexpert and maximize Expert assignments. In ASP, we minimize a sum of weights. For Inexpert, we assign a positive weight; for Expert, a negative weight (to maximize):

:~ assign(R, P), bid(R, P, Inexpert). [1@1, R, P]
:~ assign(R, P), bid(R, P, Expert). [-1@2, R, P]

The first weak constraint adds a penalty of 1 for each Inexpert assignment (we want to minimize). The second subtracts 1 for each Expert assignment (effectively maximizing). The @ levels indicate priority: here we give higher priority to maximizing Expert (level 2) over minimizing Inexpert (level 1).

Putting It All Together

Your final program should include all the rules above, plus the necessary input declarations. Remember to document each rule as required in Task 1.1. For Task 1.2, you need to explain the design and functioning of your program, describing how each rule is evaluated and how the guess-and-test methodology is implemented.

Example Input and Output

Suppose we have three referees (r1, r2, r3) and two requests (p1, p2) with bids:

bid(r1, p1, Expert).
bid(r2, p1, Knowledgeable).
bid(r3, p1, Inexpert).
bid(r1, p2, Familiar).
bid(r2, p2, Expert).
bid(r3, p2, Knowledgeable).

With n=2, m=1, k=1, a possible optimal assignment might be: assign(p1, r1) and assign(p1, r2); assign(p2, r1) and assign(p2, r2). This gives workloads: r1=2, r2=2, r3=0 (difference 2 > m=1, so invalid). Another assignment: assign(p1, r1) and assign(p1, r2); assign(p2, r2) and assign(p2, r3). Workloads: r1=1, r2=2, r3=1 (max diff=1). Familiar count: r1 has one Familiar (p2) which is ≤k=1. Expert count: r1 Expert on p1, r2 Expert on p2 → total 2. Inexpert count: 0. This is a valid optimal solution.

Conclusion

By following the guess-and-test methodology, you can elegantly encode complex constraints in ASP. This approach is widely used in AI planning, scheduling, and configuration problems. As you work on the CMT304 assignment, remember to test your program with various inputs and pay attention to optimization priorities. Good luck!