matlab 数学建模 排课.docx
matlab 数学建模 排课TOMLAB课表编排问题 我们老师让我们做一个课表编排问题,题目见 我试图用基于MATLAB的一个软件TOMLAB做,因为他有一个例子:见 由于我对MATLAB、TOMLAB应用不熟练,我试图先写一个程序尽可能和例子相似。 我将问题简化,先安排第一类课程,有三个老师,5门课。并且我不考虑教室问题。由于每堂课是以两个课时为一个单位,五门课每周分别上2 2 322堂课,每个老师教任意的课,他们的每周最大课时数分别是2 2 3,每天可以上4节课 优化目标: 1:最好在每天的第2、3节安排课程,第一节、第四节尽可能不安排课 2:尽可能满足老师们的最大课时数,使他们加班尽可能少。 程序 teacher=1 2 3; lesson=1 2 3 4 5; lesson_times=2 2 3 2 2; slots=4*5; t=tomArrayIdx('t',1:3); l=tomArrayIdx('l',1:length(lesson); s=tomArrayIdx('s',1:20); teach=tomArray('teach',3,5,20); %create a array of 3*5*20 (teacher*lesson*slots) bnds1=0<=teach<=1; % All variables are binary bnds2=sum(sum(teach(t,l,s),s),t)=lesson_times; %所有的课程必须全部安排进课表 bnds3=sum(sum(teach(t,l,s),t),l)<=1; % Teacher constraint, one teacher per slot bnds=bnds1,bnds2,bnds3; not_so_good_slots=tomArrayIdx('l',1,4,5,8,9,12,13,16,17,20); objective1=sum(vec(teach(l,t,not_so_good_slots); %the goal is to minimize teaching courses in these no so good slots max_work=2 2 3; objective2=0; for i=1:3 overwork=sum(sum(teach(i,l,s),s),l)-max_work(i) if overwork>0 objective2=objective2+10*abs(overwork); end end 但是,当我输入objective1=sum(vec(teach(l,t,not_so_good_slots);后,提示: Error in => tomArray.subsref at 78 checkIndexes(o); 我输入 for i=1:3 overwork=sum(sum(teach(i,l,s),s),l)-max_work(i) if overwork>0 objective2=objective2+10*abs(overwork); end end 后提示 ? Function 'gt' is not defined for values of class 'tomArray'. Error in => gt at 18 varargout1:nargout = builtin('gt', varargin:);