You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

stable roommate问题变体:房间依赖偏好的三维配对求解技术问询

Great question—this context-dependent twist on the classic stable roommate problem (SRP) is super interesting, and there are actually several adapted techniques from matching theory that can tackle it. Let’s break this down clearly:

Key Problem Framing

First, let’s name what you’re dealing with: this is a context-dependent stable roommate problem with room preferences. It blends elements of SRP (pairing students) and house allocation (choosing rooms), with the unique twist that a student’s preferred partner changes based on which room they’re considering.

Relevant Techniques & Models

Here are the most practical approaches to solve this:

  • Extended Gale-Shapley Algorithm: The classic Gale-Shapley can be modified to account for dual preferences. Instead of students having a single global partner list, each student maintains a separate partner preference list for every room, plus their own ranked list of rooms. The algorithm works by having students propose to "partner-room" combinations (e.g., "I want to pair with B in Room 1") based on their top room first, then top partner in that room. Partners can accept or reject proposals, iterating until no more changes are possible.
  • Stable Matching with Externalities: This problem falls into the category of matching with externalities—where the value of a partner depends on an external factor (here, the room). Researchers have developed iterative improvement algorithms for this: start with any feasible assignment, then repeatedly eliminate blocking triples (we’ll define these below) until no more exist.
  • Integer Programming (IP) Formulation: For smaller-scale problems (e.g., a class of 20 students), you can model this as an IP problem. Define binary variables for every possible (Student X, Student Y, Room R) triple (indicating if X and Y are paired in R). Add constraints to ensure each student is in exactly one pair/room, each room doesn’t exceed its capacity, and no blocking triples exist. You can optimize for maximum preference satisfaction or strict stability.
Step-by-Step Guide to Assigning Pairs & Rooms

Let’s walk through how to implement this in practice:

  1. Formalize All Preferences

    • Collect from every student:
      • A ranked room preference list: R1 ≻_S R2 ≻_S ... ≻_S Rn (read as "Student S prefers Room 1 over Room 2, etc.")
      • For each room R, a ranked partner preference list: P_S(R) = [S1 ≻_S(R) S2 ≻_S(R) ...] (who S wants to room with most in R)
    • Confirm room capacities (e.g., each room holds exactly 2 students = 1 pair).
  2. Define Stability to Avoid Conflicts
    A stable assignment means there are no blocking triples: a set of two students (X, Y) and a room R where:

    • X and Y are not currently paired together in R
    • X would rather pair with Y in R than stay in their current pair/room
    • Y feels the same way about pairing with X in R
    • Room R is at least as preferable to both X and Y as their current assigned room
  3. Run Your Chosen Algorithm

    • For large groups: Use the extended Gale-Shapley. Start with students proposing to their top room’s top partner, resolve accept/reject, and iterate until no more proposals are made.
    • For small groups: Use the IP model (tools like Gurobi or even Excel Solver can handle this) to find an optimal stable assignment.
  4. Validate & Adjust
    After getting an initial assignment, check for blocking triples manually (or via code). If any exist, adjust the pairs/rooms to eliminate them—repeat until the assignment is stable.

Quick Example to Illustrate

Suppose we have 2 rooms (R1, R2) and 4 students (A, B, C, D):

  • A’s room preference: R1 ≻ R2; A’s R1 partner list: B ≻ C; A’s R2 partner list: D ≻ B
  • B’s room preference: R2 ≻ R1; B’s R1 partner list: A ≻ C; B’s R2 partner list: A ≻ D

Here’s how extended Gale-Shapley would work:

  1. A first proposes to B in R1 (their top room + top partner). B accepts temporarily (no current assignment).
  2. B’s top room is R2, so B proposes to A in R2. A’s room preference ranks R1 higher than R2, so A rejects.
  3. D proposes to A in R2 (D’s top room + top partner). A rejects since they’re already paired in R1 (their preferred room).
  4. C proposes to B in R1, but B is already paired with A, so B rejects.
  5. Final stable assignment: (A,B) in R1, (C,D) in R2. No blocking triples exist here!

内容的提问来源于stack exchange,提问作者ZZ1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:37:22