Modeling the shift types in Staff schedulling with linear programming - linear-programming

So i want to solve problem ,that looks like nurse scheduling Problem, the different is that there is 2 type of Workers, who should work minimum 40 hours per week, the other type should work minimum 10 hours per week.
In order to solve this problem with simplex , i have to define the shifts(shift types). the shifts in a day should be minimum 3 hours and maximum 9 hours.
this photo is what i have tried so farShifts
And total of shift types would be 55. and if i multiply that to the number of workers and days. that would be 15000 variables. is it possible to solve a problem like this, or should i try to do it other way?
Has anyone suggestion?

You have a nurse example at CPLEX_Studio129\opl\examples\opl\nurses.
To do what you need you need to change
//global max worked time
forall(n in Nurses)
ctNurseMaxTimeConstraints:
NurseWorkTime[n] <= MaxWorkTime;
into
forall(n in Nurses)
ctNurseMaxTimeConstraints:
NurseWorkTime[n] <= n.MaxWorkTime;
where maxWorkTime is not global but per nurse. 15000 binary decision variables should be fine.

Related

Saving from nonlinearity in GAMS

I am trying to overcome a machine allocation problem with time horizon of 5 day. Production plan is hard to catch up, so my objective is to minimize total machines working time spent. Machines uses molds to produce and there are molds for each type of product. If a product is produced at the end of the day and if there will be production later day, total setup needed for that machine should be decreased by one. For this reason,
sets
i: mold type
j:jobs
k: days
parameters
x(i,k) ith mold production needed at day k
y(i,j) 1 if ith mold is compatible with jth machine
Decision variable
m(i,j,k) : 1 if ith mold processed in jth machine in day k 0 o/w
b(j,k) setup number of jth machine in day k
While computing the setup number for day 1, b(j,’1’), is simply equal to the sum of m(i,j,k).
For computing other days setup number I tried these but these made problem nonlinear and it takes months to solve.
b(j,'2')=e=sum(i,m(i,j,'2')) - sum(i,m(i,j,'2')*m(i,j,'1'))
By this way, if mold i is produced in both days, there will not be any setup made at second day. In order to restrain multiple setup reduction I put: sum(i,m(i,j,'2')*m(i,j,'1')) =l= 1
So, how can I decrease the setup number for a machine if it has used a mold a day before without making the problem nonlinear.
It is possible to linearize m(i,j,'2')*m(i,j,'1'):
Both(i,j) <= m(i,j,'2')
Both(i,j) <= m(i,j,'1')
Both(i,j) >= m(i,j,'2')+m(i,j,'1')-1
Both(i,j) is a binary variable
This transformation is done automatically by some solvers.
Note that there are alternative ways to model the start of a run, and often there are things to exploit (depending on the details).

Checking the time in ORACLE APEX 5.1

I'm am new to apex and I'm working on a food ordering application where customers are permitted to change their order details only up to 15 minutes after the order has been placed. How can I implement that ?
Create a validation on date item. Calculate difference between SYSDATE (i.e. "now") and order date. Subtracting two DATE datatype values results in number of days, so multiply it by 24 (to get hours) and by 60 (to get minutes). If that result is more than 15, raise an error.
To provide an alternative to Littlefoot's answer, timestamp arithmetic returns interval literals, if you use SYSTIMESTAMP instead your query could be:
systimestamp - order_date < interval '15' minute
or, even using SYSDATE something like:
order_date > sysdate - interval '15' minute
One note, the 15 minutes seems somewhat arbitrary (a magic number) it relies on the order not starting to be processed within that time limit. It feels more natural to say something like "you can change your order until the kitchen has started cooking it". There's no need for any magic numbers then and considerably less wastage (either of the customers time always waiting 15 minutes or of the kitchen's resources cooking something they may then have to discard).

How to record total values with rrdtool

I'm pretty sure this question has been asked several times, but either I did not find the correct answer or I didn't understand the solution.
To my current problem:
I have a sensor which measures the time a motor is running.
The sensor is reset after reading.
I'm not interested in the time the motor was running the last five minutes.
I'm more interested in how long the motor was running from the very beginning (or from the last reset).
When storing the values in an rrd, depending on the aggregate function, several values are recorded.
When working with GAUGE, the value read is 3000 (10th seconds) every five minutes.
When working with ABSOLUTE, the value is 10 every five minutes.
But what I would like to get is something like:
3000 after the first 5 minutes
6000 after the next 5 minutes (last value + 3000)
9000 after another 5 minutes (last value + 3000)
The accuracy of the older values (and slopes) is not so important, but the last value should reflect the time in seconds since the beginning as accurate as possible.
Is there a way to accomplish this?
I dont know if it is useful for ur need or not but maybe using TREND/TRENDNAN CDEF function is what u want, look at here:
TREND CDEF function
I now created a small SQLite database with one table and one column in that tabe.
The table has one row. I update that row every time my cron job runs and add the current value to the current value. So the current value of the one row and column is the cumualted value of my sensor. This is then fed into the rrd.
Any other (better) ideas?
The way that I'd tackle this (in Linux) is to write the value to a plain-text file and then use the value from that file for the RRDTool graph. I think that maybe using SQLite (or any other SQL server) just to keep track of this would be unnecessarily hard on a system just to keep track of something like this.

Most efficient way to process complex histogram data?

I'm currently implementing a histogram that will show a very large scale data using Qt and I have some doubts about which data structure(s) I should be using for my problem. I will be displaying the amount of queries received from users of an application and the way I should display is as follows -in a single application that will show different histograms upon clicking different "show me this data etc." buttons-
1) Display the histogram of total queries per every month -4 months of data here, I
kept four variables and incremented them as I caught queries belonging to those months
in the CSV file-
2) Display the histogram of total queries per every single day in a selected month -I was thinking of using 4 QVectors to represent the months for this one, incrementing every element of the vector (day), as I come by that specific day -e.g. the vector represents the month of August and whenever I come across a data with 2011-08-XY , I will increment the (XY + 1)th element of that vector by 1- my second alternative is to use 4 QLinkedList's for the sake of better complexity but I'm not sure if the ways I've come up with are efficient enough and I'm willing to listen to any other idea.
3) Here's where things get a bit complicated. Display the histogram of total queries per every hour in a selected day and month. The data represented is multiplied in a vast manner and I don't know which data structure -or combination of structures- I should use to implement this one. A list of lists perhaps?
Any ideas on my problems at 2) and 3) would be helpful, Thanks in advance.
Actually, it shouldn't be too unmanageable to always do queries per hour. Assuming that the number of queries per hour is never greater than the maximum int value, that's only 24 ints per day = 32 bits or 64 depending on your machine. Assuming 32 bits, then you could get up to 28 years worth of data per MB.
There's no need to transfer the month/year - your program can work that out. Just assign hour 0 to the earliest point in your data, which you keep as a constant, then work out the date based on hours passed since then.
This avoids having to have a list of lists or anything fancy - just use an array where each address contains the number of hours since hour 0, and the number of queries for that hour.
Why don't you simply use a classical database?
When you start asking these kind of question I think it is a good time to consider a more robust structure.There are multiple data structures implemented inside any DB, optimized either for different access type. You should considerate at least lookup, insertion, deletion, range queries. There is no structure which is better than the others in all costs, so there is always a trade-off.
Qt has some database classes you can use. I never used the Qt SQL library, but I think you should give it a shot. Fortunately, there is a Qt SQL programming guide at the end of the page linked.

average hourly traffic over the year

After hours of searching the web (including SO), I am requesting advice from the community. RRD seems to be the right tool for this, but I could not get a straight answer until now.
My question is : Is it possible to get RRD output a graph for the day, that averages data from the past year ?
In other words, I want the "view span" to be one day long, but the "data span" to extend over the last 12 months, so that for 6pm, the value will be computed as the average value of ALL previous traffic measured at 6pm last 12 months.
Any hints, or instructions welcomed!
There is no direct way to create such a graph, at least in theory it would be possible using multiple DEF lines together with the SHIFT operation to create such a chart ... you would have to use a program to create the necessary command line though