2016-05-01 19 views
0

Ich bin neu in MiniZinc und ich habe Probleme mit einer Implementierung der folgenden CP FormulierungMiniZinc - Aufgabenplanung auf mehreren Einrichtungen - kumulativ ‚var opt error‘

(vollständige Formulierung des Problems kann here (page 4/16) zu finden)

CP formulation of the problem

Meine Implementierung scheint, wie Code unten, aber ich habe Kampf mit folgenden Fehlern: MiniZinc: type error: no function or predicate with this signature found: 'comulative(array[int] of var opt int,array[int] of var opt int,array[int] of var opt int,int)'.

Dies liegt daran, Array-Verständnis wird von einigen Variablen beeinflusst, in diesem Fall Variable x.

Haben Sie Vorschläge, wie Sie cumulative Constraint mit Optionsvariablen oder einer möglichen Umgehungslösung arbeiten lassen?

Vielen Dank im Voraus für Ihre Hilfe :-)

include "cumulative.mzn"; 
include "element.mzn"; 

int: numJ; % number of tasks 
int: numI; % number of facilities 

% Tasks 
set of int: Tasks = 1..numJ; 

% Facilities 
set of int: Facilities = 1..numI; 

% Max consumptions of facilities 
array[Facilities] of int: C; 

array[Tasks] of int: d; % due times 
array[Tasks] of int: r; % release times 
array[Facilities, Tasks] of int: c; % c[i,j] = consumption of task j at facility i 
array[Facilities, Tasks] of int: p; % p[i,j] = processing time of task i at facility j 
array[Facilities, Tasks] of int: F; % F[i,j] = fixed cost paid when task j is assigned to facility i 

% start time's domain is an interval <0, maximum of due times> 
array[Tasks] of var 0..max(d): s; 

% assign task to a facility 
% x[3] = 1 --> task 3 is assigned to facility 1 
array[Tasks] of var 1..numI: x; 

% something like a temporary processing time 
% im not really sure about this 
array[Tasks] of var 0..max(p): u; 

constraint forall(j in Tasks)(
    element(
    x[j], 
    [p[i,j] | i in Facilities], 
    u[j] 
) 
); 


constraint forall(i in Facilities)(
    comulative(
    [s[j] | j in Tasks where x[j] == i], 
    [p[i,j] | j in Tasks where x[j] == i], 
    [c[i,j] | j in Tasks where x[j] == i], 
    C[i] 
) 
); 




% A task cant start before its release time 
constraint forall(j in Tasks)(s[j] >= r[j]); 
% A task cant run longer than its due time 
constraint forall(j in Tasks)(s[j] <= d[j] - u[j]); 

% Minimize total cost 
solve minimize sum(j in Tasks)(F[x[j],j]); 

output [ "start: ", "\n", show(s), "\n", "facility: ", "\n" , show(x) , "\n"]; 

Einfacher Datensatz:

C = [8, 8, 6, 5]; 

numJ = 12; 
numI = 4; 
r = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]; 

d = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3]; 

c = [|8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |]; 

p = [|1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |]; 

F = [|0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, |]; 
+2

Nur eine Anmerkung: die Einschränkung wird als "kumulative" (nicht "comulative"). Die Änderung des korrekten Namens führt jedoch immer noch zur gleichen Fehlerart, da die Segmente wie "[s [j] | j in Tasks mit x [j] == i]" kumulativ in "var opt int" (was in der kumulativen Einschränkung nicht unterstützt wird). Ich werde sehen, ob ich mir ein Arbeitsmodell ausdenken kann. – hakank

+0

Eine andere Sache: Haben Sie ein vollständiges Beispiel mit den festen Parametern, z. numJ, numI, C, d, r, c, p und F? – hakank

+0

@hakank Ich habe eine einfachere Lösung entwickelt, die keine kumulativen oder Element-Constraints verwendet, sondern nur imitiert. Ich werde diese Frage in einem Moment selbst beantworten. – mrtn

Antwort

2

Auch wenn Sie erwähnten, dass Sie eine Lösung gefunden haben, hier ist eine Version, die kumulativ verwenden (opt-Version in "kumulative_opt.mzn").

include "globals.mzn"; % includes the file "cumulative_opt.mzn" 
% .... 

constraint forall(i in Facilities)(
    cumulative(
    % [s[j] | j in Tasks where x[j] == i], % original 
    % [p[i,j] | j in Tasks where x[j] == i], % original 
    % [c[i,j] | j in Tasks where x[j] == i], % original 

    [s[j] | j in Tasks where x[j] == i], 
    [p[i,j] | j in Tasks], % <-- no condition clause here 
    [c[i,j] | j in Tasks], % <-- no condition clause here 
    C[i] 
) 
); 
+0

Ich verbrachte 7 Stunden damit, nach einer Antwort zu suchen, wie man 'kumulative' Constraint mit opt-Werten arbeiten kann und nicht das kumulative_opt überhaupt bemerkt hat. Danke für Ihre Hilfe :) – mrtn

+0

:-) Ich neige dazu, das Verzeichnis der globalen Constraint-Dateien (* .mzn) im Verzeichnis "share/minizinc/std" zu durchsuchen, um zu sehen, ob es eine entsprechende Einschränkung gibt. Und manchmal schauen Sie sich den Eintrag unter http://www.minizinc.org/2.0/doc-lib/doc.html an. – hakank

1

Ich kam mit dieser Lösung und ich hoffe, es ist leichter zu verstehen als die mit kumulativer Einschränkung.

array[Facilities, 0..max(d)] of var 0..max(C): facilityUsageAtTime; 

constraint forall(i in Facilities) (
    forall(tt in 0..max(d)) (
     facilityUsageAtTime[i,tt] = sum(j in Tasks where x[j] == i /\ s[j] <= tt /\ tt < s[j] + p[x[j], j])(c[x[j],j]) /\ 
     facilityUsageAtTime[i,tt] <= C[i] 
    ) 
); 

Es stark von @hakank Antwort inspiriert geschrieben here