优化方法的组分配问题

时间:2018-10-29 17:52:48

标签: optimization cplex ampl lindo

有一家公司举办研讨会,将有60名学员参加。公司计划将参与者分为10组,每组6名学员。事先要求每位学员选择与他们合作的5位学员。并且这五个中的每个均被加权。 问题在于我们如何将参与者分为几组,以便可以优化总满意度。

1 个答案:

答案 0 :(得分:-1)

让我给您一个关于OPL CPLEX中CPO的小例子:

//There’s a company organising a seminar, where 60 trainees will attend. 
//The company plans to divide the participants into 10 groups, each of 6 trainees. 
//Each of the trainees was asked beforehand to choose 5 other trainees they would like to work with. 
//And each of the five is weighted equally. 
//The problem is how we can assign the participants into groups so that the total satisfaction could to optimised. 

using CP;

execute
{
cp.param.timelimit=20;
}

int nbTrainees=60;
int nbGroups=10;
int nbWishes=5;
int sizeGroup=nbTrainees div nbGroups;



range trainees=1..nbTrainees;
range groups=1..nbGroups;
range likes=1..nbWishes;

// let us start with the nbWishes next trainees
int wishes[t in trainees][w in likes]=(t+w-1) mod nbTrainees+1;

assert forall(t in trainees,w in likes) wishes[t][w] in trainees;
assert forall(t in trainees,w in likes) wishes[t][w] != t;

// a gievn trainee belongs to a given group ?
dvar boolean x[trainees][groups];

dvar int satisfaction;

maximize satisfaction;
subject to
{

// trainees belong to one and only one group
forall(t in trainees) sum(g in groups) x[t][g]==1;

// group size
forall(g in groups) sum(t in trainees) x[t][g]==sizeGroup;

// satisfaction formula
satisfaction==sum(t in trainees,w in likes,g in groups) ((x[t][g]*x[wishes[t][w]][g]));

}

{int} team[g in groups]={ i | i in trainees : x[i][g]==1};

execute
{
writeln(team);
}