How to implement a priority queue that still meets other requirements?

1

I need to implement a priority queue, this queue in addition to the priority, needs to take into account some other requirements, such as switching between services and professionals, in addition to respecting the customer's order of arrival for that service and / or professional. p>

My complete (hypothetical) scenario:

In a hospital we have three services offered (this in any other company can be the same situation, a law firm anyway.):

Consultations, exams to be done in the day and another service that is a schedule of exams.  The system needs to switch between services, type, called someone's query, the next should be from any other service and so on. The system must also switch between professionals, the one previously called was from professional 1, the next should be from professional 2 and so on.

I have been researching some lib or some algorithm and the closest one I found was the heapq of Python but I could not adapt and mount my solution.

I'm really in need of a help, I accept suggestions for implementations, indications of libs that solve this problem anyway.

I have tried several solutions and none have shown the desired result.

I'm waiting for you.

PS: I did several searches here in the OS and I did not find any of the same question, if it is repeated please indicate link of the question.

    
asked by anonymous 02.07.2017 / 15:46

1 answer

0

I can imagine some ways to solve this - but it's complicated: a professional development task - it would be a long way from responding here. And - suddenly time would be better engaged in creating a small Python package that could do this, instead of getting to write a functional example here.

To give you some tips: Python's "heapq" usually only compares the object itself (eg "plug number") - a first step, if you choose to use heapq, is to pass a function that can have complex rules - just as we can pass the parameter "key" to sorted . I have an answer in S.O. in English that creates a small heapq wrapper classse that facilitates this: link

Now, your key function would have to take into account information that is external to the element it is comparing - for example: what was the last sub-queue called, and what was the last called - the function key of the sorted only receives the element itself - without being able to look at the rest of the queue. In this case, you have to take advantage of having a custom class, instead of accepting the "key" as a parameter of __init__ as in the example I passed, do the key function within the class itself: and it will be able to look within the elements that are already in the queue to take into account the other factors.

Another thing you can look at is " redis - it will allow you to maintain a persistent queue between distinct HTTP requests - even though you have multiple machines serving the requests for your application (or multiple processes and threads - which is normal in a production environment).

    
03.07.2017 / 12:15