1 /*
2  * Task.java
3  * This file is part of JaCoP.
4  * <p>
5  * JaCoP is a Java Constraint Programming solver.
6  * <p>
7  * Copyright (C) 2000-2008 Krzysztof Kuchcinski and Radoslaw Szymanek
8  * <p>
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  * <p>
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  * <p>
19  * Notwithstanding any other provision of this License, the copyright
20  * owners of this work supplement the terms of this License with terms
21  * prohibiting misrepresentation of the origin of this work and requiring
22  * that modified versions of this work be marked in reasonable ways as
23  * different from the original version. This supplement of the license
24  * terms is in accordance with Section 7 of GNU Affero General Public
25  * License version 3.
26  * <p>
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 package org.jacop.constraints;
32 
33 import org.jacop.core.IntDomain;
34 import org.jacop.core.IntVar;
35 import org.jacop.core.IntervalDomain;
36 
37 /**
38  * Represents tasks for cumulative constraint
39  *
40  * @author Krzysztof Kuchcinski and Radoslaw Szymanek
41  * @version 4.8
42  */
43 
44 class Task {
45 
46     final IntVar start, dur, res;
47 
Task(IntVar start, IntVar duration, IntVar resourceUsage)48     Task(IntVar start, IntVar duration, IntVar resourceUsage) {
49         this.start = start;
50         this.dur = duration;
51         this.res = resourceUsage;
52     }
53 
areaMax()54     long areaMax() {
55         return dur.max() * res.max();
56     }
57 
areaMin()58     long areaMin() {
59         return dur.min() * res.min();
60     }
61 
compl()62     IntDomain compl() {
63         IntDomain sDom = start.dom();
64         IntDomain dDom = dur.dom();
65         return new IntervalDomain(sDom.min() + dDom.min(), sDom.max() + dDom.max());
66     }
67 
completion()68     IntDomain completion() {
69         IntDomain sDom = start.dom();
70         int dDomMin = dur.dom().min();
71         return new IntervalDomain(sDom.min() + dDomMin, sDom.max() + dDomMin);
72     }
73 
dur()74     IntVar dur() {
75         return dur;
76     }
77 
ect()78     int ect() {
79         return start.min() + dur.min();
80     }
81 
est()82     int est() {
83         return start.min();
84     }
85 
lastCT()86     int lastCT() {
87         return start.max() + dur.max();
88     }
89 
lct()90     int lct() {
91         return start.max() + dur.min();
92     }
93 
lst()94     int lst() {
95         return start.max();
96     }
97 
minUse(IntTask t)98     boolean minUse(IntTask t) {
99         int lst, ect;
100         IntDomain sDom = start.dom();
101 
102         lst = sDom.max();
103         ect = sDom.min() + dur.min();
104         if (lst < ect) {
105             t.start = lst;
106             t.stop = ect;
107             return true;
108         } else
109             return false;
110     }
111 
res()112     IntVar res() {
113         return res;
114     }
115 
start()116     IntVar start() {
117         return start;
118     }
119 
nonZeroTask()120     boolean nonZeroTask() {
121         return dur.min() > 0 && res.min() > 0;
122     }
123 
toString()124     @Override public String toString() {
125         return "[" + start + ", " + dur + ", " + res + "]";
126     }
127 
128 }
129