Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I have a java web application that has to deals with resource management.
FOr Example
Dept Min Max Resource Effective Date Last Date
HR 1 3 Alex 08/19/2013 12/31/2013
HR 1 3 Adam 08/19/2013 12/31/2013
IT 2 5 Jade 08/19/2013 10/31/2013
IT 2 5 Robert 11/01/2013 12/31/2013
IT 2 5 Lisa 08/19/2013 12/31/2013
I have different departments which has preset min/max employees I can allocate as a manager. So HR- dept has min of 1 and max of 3, I have allocated 2 from today to end of year.
In IT dept I have allocated a partial dates for Jade and robert to count them as 1 for entire period. Lisa for end-to end. which together is 2 which is in the min/max range.
Basically, the bottom line is at any point of time I have to make sure allocation will not violate the min/max rule. So, I want suggestions about how to validate these kind of scenarios in java application. Any open source API you found useful.
If I understood your question right, you basically want to find out which intervals overlap. Concerning dates, I normally tend to use http://joda-time.sourceforge.net/ since it has a very clean and nice API compared to out-of-the-box java Date.
Joda time also offers Intervals and a method to check if intervals overlap: http://joda-time.sourceforge.net/apidocs/org/joda/time/Interval.html#overlap(org.joda.time.ReadableInterval)
Nevertheless it didn't work for me as I wanted to check on a per-day basis, thus I had to implement it myself, using Joda time Intervals as base objects:
public static boolean checkInteraction(Interval one, Interval another) {
return ((one.getEnd().equals(another.getStart()) || one.getEnd().isAfter(another.getStart())) &&
(another.getEnd().isAfter(one.getStart()) || another.getEnd().equals(one.getStart())));
}
Having this in place, you can go through the intervals and check if they overlap/interact and check if it exceeds your max number.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So i have an opera houses with 10 rows and 10 columns of seats (Total :100). Each seat is allocated a preference value Aij. The preference value is halved if the group do not get seats in same row. Eg: If a reservation in opera house is for 5 people and only 2 can be accommodated in top row and 3 in next row, the preference value is actually halved for each seat. There are total of n reservations with 'n' > 100 seats. What will the best way to maximize the customer preference (n *Aij).If it can be done by linear programming, how should the equation look like.
I think this is not trivial to model as a MIP.
I gave it a try using a main binary variable x(i,j,g,r) where (i,j) is the row and column of the seat assigned to group g. The set r is {singlerow,multiplerows} to indicate whether the group is sitting in the same row.
Not sure if this is a particular good formulation, but it seems to work. Below are the equations I used:
I assumed that there are a number of groups g that each have a size. A group gets all seats it needs or it is not getting any seats.
I suspect that a constraint programming approach could be easier.
Conclusion: it can be done using a MIP formulation but it is somewhat cumbersome.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I'm working on a book for Manning and want to use Alchemy News API as part of one of the examples. I have a free license which says it allows for 1,000 transactions per day. Does that mean 1,000 queries or something else? I hit the limit today way earlier than I expected to, at significantly less than 1,000 queries.
Each type of call has different amounts of transactions it uses. The text analysis uses just 1 transaction but the image analysis uses more. I believe it used about 5 transactions per image but it's been awhile since I've used the image recognition.
The number of transactions used is given in the response from AlchemyAPI. It also gives you more details in the documentation.
Query Cost + Result Cost = Total Cost
This is something I learnt today. Therefore you'll run out of transactions easily with loads of data. Keep your queries to a minimum.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
What is the best practice to manage time intervals in Oracle? For example: I have a room that will be rented between 8:15 till 9:00. So I have at least 2 fields: dt_start and dt_end, I suppose. I can not permit to enter a rent between 8:45 till 9:20. So how would be the best table structure for that? Thanks
There is no clear consensus on the best way to implement this. The answer certainly depends a great deal on your exact situation. The options are:
Table with unique constraint on ROOM_ID and a block of time. This is only realistic if the application allocates a reasonably small amount of time using reasonably large blocks. For example, if a room can only be allocated for at most a week, 5 minutes at a time. But if reservations are to the second, and can span over a year, this would require 31 million rows for one reservation.
Trigger. Avoid this solution if possible. The chance of implementing this logic in a trigger that is both consistent and concurrent is very low.
Materialized view. This is my preferred approach. For example, see my answer here.
Enforced by the application. This only works if the application can serialize access and if no ad hoc SQL is allowed.
Commercial Tool. For example, RuleGen.
BEFORE INSERT TRIGGER is the best way to accomplish your need.
In trigger, figure out that the new time is not conflicting the current time of your particular room, and if so you can Rais Error, otherwise let the update happen.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Suppose I want to write an application to compose music.
I'd like to feed a set of musical scores of a composer - e.g. Bach's Well tempered clavier' - and the program should prepare new scores in a similar style.
Are algorithms or even libraries known for this task?
WikiPedia provides this page about algorithmic music composition.
You could make something basic using Markov chains. The principle is to first produce some unit of music (a single note, for example) and then, based on the last produced unit, randomly select the next unit.
First, pass through the input music. Each time you see a particular note/other unit of music, simply record in the table what came after it. When you have gone trough the entire input material, you will have a frequency table of which units follow which (After 'A', 'B' appeared 29 times, 'C' appeared 12 times and 'A' appeared twice; after 'B' ... etc).
Now select an initial note. Select the next one randomly according to the frequencies recorded in the table. Repeat until satisfied.
This will probably not yield good results if applied to individual notes, instead try short phrases. Also, the quality will improve if you have access to a large corpus of source music.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Well I have been asked to validate passport numbers (the documents used on airports to travel to other countries).
My question is: What format are these "numbers"? All I know is that they can have letters but I am not finding any place defining the rules. Any pointers/Links?
I don't think you're going to be able to do this without restricting yourself to certain issuing countries. If you look at the specs of machine readable passports:
http://www.highprogrammer.com/alan/numbers/mrp.html
It says that each country is free to use any format it likes for the actual passport number (including letters or digits). Although in the machine readable schema these seem to be limited to 9 characters (which might cause problems for countries with billions of citizens if they were to just use digits!)
I would expect the format to depend on the issuing country.
UK passport numbers consist of 9 digits but used to consist of 6 digits and a letter.