da ich gerade etwas Probleme mit dem zweiten Übungsblatt habe und auch als Mac Nutzer kein ILOG installieren kann um meine Lösungen zu überprüfen, möchte ich in diesem Thread meine Lösungen mit euch teilen.
Zuerst mein Code für das erste Übungsblatt:
Code: Alles auswählen
// aufgabe 1
struct tuple {
int x;
int y;
};
int+ anzahl_punkte = ...;
range indices 1..anzahl_punkte;
Point punkte_in [indices] =...;
var Point left_lower;
var Point right_upper;
var float+ area_rectangle;
minimize area_rectangle subject to
{
forall (i in indices) punkte_in[i].x >= left_lower.x
forall (i in indices) punkte_in[i].x <= right_upper.x
forall (i in indices) punkte_in[i].y >= left_lower.y
forall (i in indices) punkte_in[i].y >= right_upper.y
area_rectangle = abs(right_upper.x - left_lower.x) * abs(right_upper.y - left_lower.y)
};
// aufgabe 2
int wasserstoff = 170;
int kohlenstoff = 1000;
int gewinnn_methan = 80;
int gewinn_ethan = 100;
var int+ hergestelltes_methan in 0..maxint;
var int+ hergestelltes_ethan in 0..maxint;
var int+ gewinn_total in 0..maxint;
maximise gewinn_total subject to
{
hergestelltes_methan * 4 + hergestelltes_ethan * 6 <= wasserstoff;
hergestelltes_methan * 12 + hergestelltes_ethan * 24 <= kohlenstoff;
gewinn_total = hergestelltes_ethan * gewinn_ethan + hergestelltes_methan * gewinnn_methan;
};
// task 3 a)
int+ N = ...;
int+ n = ...;
range indices 1..n;
int+ values[indices] in 1..N;
solve
{
forall (i in indices, j in indices) i <> h => values[i] <> values[h]
};
// task 3b)
int+ N = ...;
int+ n = ...;
int+ m = ...;
range indices_x 1..n;
range indices_y 1..n;
int+ values[indices_x, indices_y] = ...;
solve
{
forall (i_x in indices_x, i_y in indices_y, j_x in indices_x, j_y in indices_y) i_x <> j_x \/ i_y <> j_y => values[i_x,i_y] <> values[j_x,j_y]
}
EDIT ich habe meine Fragen teilweise selbst gelöst, mein neues Modell sieht so aus
Code: Alles auswählen
struct Lecturer {
int+ min_inventar_requirement;
}
struct Slot {
float+ begin;
/*
duration 1h eg. a Slot with begin=8.5 will be between 8.30am and 9.30am on the frist day of the week
and slot with begin=32.5 will take place on 8.30am on tuesday
*/
}
struct Lecture {
int+ sws; // in hours
int+ number_of_students;
}
struct Hall {
int+ number_of_seats;
int+ inventar_level;
}
int+ number_of_lecturers = ...;
int+ number_of_slots = ...;
int+ number_of_lectures = ...;
int+ number_of_halls = ...;
range lecturers_range 1..number_of_lecturers;
range lectures_range 1..number_of_lectures;
range halls_range 1..number_of_halls;
range slots_range 1..number_of_slots;
// int+ number_of_seats [halls] = ...;
// int+ hall_inventar_level [halls] = ...;
range boolean 0..1;
Lecturer lecturer_list[lecturers_range] = ...;
Hall hall_list[halls_range ] = ...;
Slot slot_list[slots_range ] = ...;
Lecture lecture_list[lectures_range ] = ...;
Code: Alles auswählen
boolean slot_overlap_conflict [slot_range,slot_range] // 1 means conflict; 0 means no conflict
boolean lectures_in_conflict [lectures,lectures] = ...; // 1 means conflict 0 means no conflict
boolean halls_in_conflict [halls,halls] = ...; // 1 means conflict; 1 means no conflict
lecturers_range teached_by[lectures_range] = ...;
Code: Alles auswählen
var boolean time_assignment [lectures_range, slot_range]
var hall_range hall_assignment[lectures];
Code: Alles auswählen
solve {
// nur max 1 vl pro zeitslot je Hoersaal
forall (s in slot_range, t in slot_range, i in lecture_range, j in lecture_range)
i<>j => hall_asignment[i] <> hall_asignment[j] \/
(time_assignment[i,s] <> time_assignment[j, s] /\
(
(s <> t /\ time_assignment[i, s] /\ time_asignment[j, t])
=> slot_overlap_conflict[s,t] = 0
)
)
// keine überschneidene Vorlesung aus lectures_in_conflict
forall (i in lecture_range, j in lecture_range, s in slot_range, t in slot_range)
(lectures_in_conflict[i,j] /\ time_assignment[i,s] /\ time_assignment[j,t])
=> slot_overlap_conflict[s,t] = 0
// sitzplatz und teacher requirement
forall (i in lecture_range) lecturer_list[teached_by[i]].min_inventar_requirement >=
hall_list[hall_asignment[i]].inventar_level
/\ lecture_list[i].number_of_students <= hall_list[hall_asignment[i]].number_of_seats
// keine raumkonflike bei aufeinander folgende vorlesungen von einem teacher
forall (i in lecture_range, j in lecture_range, s in slot_range, t in slot_range)
(i <> j /\ teached_by[i] = teached_by[j] /\ time_assignment[i,s]
/\ time_assignment[j,t] /\ abs(slot_list[s].begin - slot_list[t].begin) <= 1.0
) => halls_in_conflict[hall_asignment[i],hall_asignment[j]] = 0
// alle sws von einer Vorlesung gesetzt
forall (l in lecture_range) sum(s in slot_range) (time_assignment[l,s]) = lecture_list[l].sws
}
1) Ist es bei der Indexierung von arrays erlaubt, ein anderes arrayelement als index zu nutzen eg. hall_list[hall_assignment] ?