2016-12-30 55 views
0

我在建模問題和用Java解決Choco求解器問題時遇到了問題,並且我不太熟悉約束編程,但是已經分配了任務爲會議製作座位應用程序,其中:如何使用Choco解算器框架爲Java建模特殊集合約束

  • 每個表必須至少有6個人,並且總是有足夠的表。
  • 人們應該與鄰居坐在一起,以最大限度地共享利益。
  • 在前幾天,我們希望儘量減少坐在桌前的人與他們坐在一起的人。
  • 人是A或B類中的任何一個,我們希望最小化每個表上A類的出現次數。

到目前爲止,我們有一個SetVar guest_list,其中包括1個客人人數。 然後將guest_list分區到SetVar []表。

但我該如何做出約束,說每個table.size> = 6?

如何在兩組之間制定約束,以最小化會員/交叉?

而且我不知道如何在集合內爲鄰居建模以最大化共享興趣。

import org.chocosolver.solver.Model; 
import org.chocosolver.solver.Solution; 
import org.chocosolver.solver.variables.IntVar; 
import org.chocosolver.solver.variables.SetVar; 

// constant value declarations 
int number_of_guests = 100; 
int table_size = 8; 
int tables_needed = number_of_guests/table_size + 1; 

// this will later be passed as argument, generated for testing 
int[] guest_ids = new int[number_of_guests]; 
for (int i = 0; i < number_of_guests; i++) { 
    guest_ids[i] = i; 
} 

// Model and variables 
Model model = new Model("Seating solver"); 

IntVar min_guests_at_tables = model.intVar(6); 
// a list containing all guests in its LB 
SetVar guest_list = model.setVar("guests", guest_ids); 
// making empty sets for each table needed, UB is all guests 
SetVar[] tables = model.setVarArray(tables_needed, new int[]{}, guest_ids); 
// log over table seatings from earlier days, starts empty for day 1. 
// want to minimize how many members from tables[x] share with any ser of logged_tables 
SetVar[] logged_tables = model.setVarArray(0, new int[]{}, new int[]{}); 
// a setvar of all interests for each guest, will be imported later. 
SetVar[] guest_interests = model.setVarArray(number_of_guests, new int[]{}, new int[]{}); 
// set of all those members of group A 
// random test values inserted 
SetVar group_A_members = model.setVar(1,23,54,2); 

// Constraints unsure about all of these 

// each set must be unique 
model.allDifferent(tables); 
for (SetVar table : tables) { 
    // TODO trying to constrain sizes of each table set to 6 or greater 
    model.arithm(model.intVar(table.getLB().size()), ">=", min_guests_at_tables); 
// TODO trying to minimize number of shared members in tables, with whats in logged_tables 
for (SetVar old_table : logged_tables) { 
    // no idea 
} 
// TODO trying to maximize the amount of interest neigbors in a set share 
// no idea 

// TODO minimize shared members from table with group_A_members 
// no idea how to minimize or maximize 
} 

// Solving 

Solution s = model.getSolver().findSolution(); 
if (s != null) System.out.println(s.toString()); 
+0

請分享任何有助於理解問題的pom.xml和代碼 –

回答

0

可用約束的集合可以從實現IConstraintFactory的模型訪問。查看源代碼中的ISetConstraintFactory.java。有與設置大小,工會,分區有關的限制...