1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  CPViz Constraint Visualization System
15// The Initial Developer of the Original Code is  Helmut Simonis
16// Portions created by the Initial Developer are
17// Copyright (C) 2009-2010 Helmut Simonis
18//
19// Contributor(s): 	Helmut Simonis, 4C, Univerity College Cork, Cork
20//
21//
22// END LICENSE BLOCK
23// ----------------------------------------------------------------------
24package ie.ucc.cccc.viz;
25
26/**
27 * Utility class to compute profiles for cumulative. This is shared by two classes which
28 * have a common ancestor only in VisualizerDrawer, so we factored this code out into
29 * a little helper routine
30 * @author hsimonis
31 *
32 */
33public class CumulativeProfile {
34
35	public static int[] computeProfile(Tuple[] task,int width){
36		int[] profile = new int[width];
37		for(int i=1;i<task.length;i++) {
38			int startMin = task[i].getField("start").getMin();
39			int startMax = task[i].getField("start").getMax();
40			int durMin = task[i].getField("dur").getMin();
41//			int durMax = task[i].getField("dur").getMax();
42			int resMin = task[i].getField("res").getMin();
43//			int resMax = task[i].getField("red").getMax();
44			if (startMin+durMin > startMax) {
45				for(int j=startMax;j < startMin+durMin;j++){
46					profile[j] += resMin;
47				}
48			}
49		}
50		return profile;
51	}
52	public static int[] computeOuterProfile(Tuple[] task,int width){
53		int[] profile = new int[width];
54		for(int i=1;i<task.length;i++) {
55			int startMin = task[i].getField("start").getMin();
56			int startMax = task[i].getField("start").getMax();
57			int durMin = task[i].getField("dur").getMax();
58//			int durMax = task[i].getField("dur").getMax();
59			int resMin = task[i].getField("res").getMin();
60//			int resMax = task[i].getField("red").getMax();
61			for(int j=startMin;j < startMax+durMin;j++){
62				profile[j] += resMin;
63			}
64
65		}
66		return profile;
67	}
68}
69