Cancel
Showing results for
Did you mean:
Highlighted

# Find the index of time interval for multiple days

Builder

I would like to divide the time into a lot of 15-minute intervals and use i to be its index. Originally, I just run the model for an 8 hour shift. So I use the code below to find i. It works, so i=1 ,2, 3, ..., 32. (8 hours have 32 15-minute intervals)

a:=time_to_num(timeofDay(EventController.AbsSimTime))-8*3600; --the simulation begins at 2013/1/1 8:00 am, AbsSimTime is absolute time which equals 0 at 2013/1/1 0:00 am
i:=a//900;

Now I need to run the model for a lot of days. I need the i to be indexed by i=1,2,...,32,33,......... Which function I should use to replace the function "TimeofDay"?

Thanks

CSW

5 REPLIES 5

# Re: Find the index of time interval for multiple days

Gears Esteemed Contributor
you could use the ShiftCalendar:

i:= time_to_num(shiftCalendar.calculateWorkingDuration(eventController.start,eventController.absSimTime))//900
 Steffen Bangsowfreelance simulation specialist  web: www.bangsow.eumail: steffen@bangsow.net

# Betreff: Find the index of time interval for multiple days

Gears Phenom

Hi CSW,

Steffen's solution considers that you only need interval-numbers during the working times; so e.g. you only have one 8hr-shift every day, then every day:

• 16:00-24:00-8:00 would not have any interval-numbers (or more precisely the same interval-number as 15:45-16:00 of the previous day!),and
• 8:00-16:00 would have 32*(numDays - 1) + {1..32} as interval numbers.

In case you need an interval number for every 15min-interval of each day, disregarding the shift-model, you could simply use

`iIntervalNumber := time_to_num(EventController.SimTime) // 900;`

The SimTime-attribute starts at 0, no matter what you set as starting datetime of the eventcontroller (so you don't have to subtract the 8hr like you did).

Regards,
Alex

___________________________________________________________
Alex Dilg, Consultant at SimPlan AG (www.SimPlan.de)
This post was good and/or helpful to you? Please provide some Kudos, thank you!

# Re: Find the index of time interval for multiple days

Legend

if timeofday(eventcontroller.abssimtime)>=21600 /*(600hrs)*/ and timeofday(eventcontroller.abssimtime)<=50400/*(1400HRS)*/ then
tm:=timeofday(eventcontroller.abssimtime);
value:=tm\\900;
if value=0 then
i:=i+1;
end;

end;

Sachin

# Betreff: Find the index of time interval for multiple days

Builder

Hi Betreff,

I used the code you suggested

i:=time_to_num(EventController.SimTime)//900;

Error happens to this line when the model is being run. It shows "integer requires integer parameter"

I pasted the codes as follows:

is
i:integer;
a:integer;
--row: integer;
--s: string;
objrow:integer;
objbject;
do
--a:=time_to_num(timeofDay(EventController.AbsSimTime))-8*3600; --the simulation begins at 2013/1/1 8:00 am, AbsSimTime is absolute time which equals 0 at 2013/1/1 0:00 am
--i:=a//900;

i:=time_to_num(EventController.SimTime)//900;

Mytable.SetDataType(1,"real");
Mytable.SetDataType(2,"real");
Mytable.SetDataType(3,"real");
Mytable.SetDataType(4,"real");

--Mytable[1,1]:="Time interval";
--Mytable[2,1]:="Cumulative Energy Consumption";
--Mytable[3,1]:="Energy Consumption each 15-min Interval";
--Mytable[4,1]:="Power Demand";

obj:= EnergyAnalyzer.EnergyConsumers;
objrow:=obj.yDim; --the total column number in EnergyConsumer (the number of machines)
Mytable[1,i]:=i; --the index of interval
Mytable[2,i]:=obj.sum ({1,1}..{1,obj.yDim}); --the cumulative energy consumption up to interval i
if i==1 then --the energy consumption of interval 1
Mytable[3,i]:=Mytable[2,i];
else
Mytable[3,i]:=Mytable[2,i]-Mytable[2,i-1]; --the energy consumptoin of interval 2,3,....
end;

Mytable[4,i]:=Mytable[3,i]*4; --the power demand of interval i
end;

# Betreff: Find the index of time interval for multiple days

Builder

I splitted the code "i:=time_to_num(EventController.SimTime)//900" into two lines

a:=time_to_num(EventController.SimTime);
i:=a//900;

Now it works.