Originally posted by: NguyenHuuTRi
Hi,
I want to write the results from three decision variables cs, f and x to excel spreadsheets but when I input the syntax in .dat it always return the error messgage excel range doe not fit array.
Hope you can help me to resolve this issue. Thanks.
Below is my model for your information.
range type = 1..3;
range course = 1..59;
range room = 1..14;
range lecture = 1..18;
range timeslot = 1..12;
range group=1..13;
int lecturetimea[lecture][timeslot] = ...;
int courselecturea[course][lecture]=...;
int courserooma[course][room]=...;
int caparooma[type]= ...;
int capa_cg[group]=...;
int coursegroupa[course][group]=...;
tuple lecture_time {
int lecture;
int time;
};
setof (lecture_time) LectureTimes =
{<l,t> | l in lecture,t in timeslot : lecturetimea[l][t]==1};
tuple course_room {
int course;
int room;
};
setof (course_room) CourseRooms =
{<c,r> | c in course,r in room : courserooma[c][r]==1};
tuple course_lecture {
int course;
int lecture;
};
setof (course_lecture) CourseLectures =
{<c,l> | c in course, l in lecture : courselecturea[c][l]==1};
tuple course_type{
int idcourse;
int idtype;
};
setof (course_type) coursetypesa = ...;
tuple course_group {
int idcourse;
int idgroup;
};
setof (course_group) CourseGroups = {<c,g> | c in course, g in group: coursegroupa[c][g]==1};
tuple lecture_course_time {
int lecture;
int course;
int type;
int time;
int room;
}
setof (lecture_course_time) LectureCourseTimes =
{<l,c,ty,t,r> | <c,l> in CourseLectures, <l,t> in LectureTimes , <c,ty> in coursetypesa, <c,r> in CourseRooms};
//sorted {lecture_course_time} s={<l,c,ty,t,r> |<c,l> in CourseLectures, <l,t> in LectureTimes , <c,ty> in coursetypesa, <c,r> in CourseRooms};
dvar boolean x[LectureCourseTimes];
dvar boolean cs[group][timeslot];
//dvar boolean csa[group][timeslot];
dvar boolean f[group][timeslot];
//dexpr int f[g][t] = sum(g in group, t in timeslot:t<=11)(cs[g][t]*(cs[g][t+1]-cs[g][t]));
//maximize sum (w in LectureCourseTimes) x[w];
minimize
sum(t in timeslot, g in group)f[g][t];
subject to
{
forall (g in group){
sum(t in timeslot)cs[g][t]==capa_cg[g];
}
forall (<l,t> in LectureTimes) {
assignLecture : sum(<l,c,ty,t,r> in LectureCourseTimes) x[<l,c,ty,t,r>] <=1;
};
forall (c in course) {
asignCourse: sum(<l,c,ty,t,r> in LectureCourseTimes) x[<l,c,ty,t,r>]<= 1 ;
};
forall (r in room, t in timeslot){
assignRoom: sum(<l,c,ty,t,r> in LectureCourseTimes)x[<l,c,ty,t,r>]<=1;
};
forall (t in timeslot, ty in type) {
asignCapaRoomType: sum(<l,c,ty,t,r> in LectureCourseTimes) x[<l,c,ty,t,r>]<= caparooma[ty];
};
forall(t in timeslot, g in group){
sum(<l,c,ty,t,r> in LectureCourseTimes)x[<l,c,ty,t,r>]*coursegroupa[c][g]==cs[g][t];
};
forall ( t in timeslot:t>=2, g in group){
(cs[g][t]- cs[g][t-1])<=f[g][t];
};
//forall ( t in timeslot, g in group){
//if (t==1) (cs[g][t]- cs[g][t-1])-1<=f[g][t] ;
//else (cs[g][t]- cs[g][t-1])<=f[g][t];
//};
forall(t in timeslot, g in group){
sum(<l,c,ty,t,r> in LectureCourseTimes)x[<l,c,ty,t,r>]*coursegroupa[c][g]<=1;
};
};
#DecisionOptimization#OPLusingCPLEXOptimizer