Specifying Resource Allocation algorithm? - matlab

Can someone help me to solve or specify what type of problem is this:
I have a set of resources and a number of users, and for each user there is a specific subset of resources that can choose a single resource from for allocation. Two different users could not be assigned to the same resource.I need to allocate resources to users in a way to maximize the allocation. for example:
R={r1,r2,r3,r4} %set of resources
U={u1,u2,u3,u4} %set of users
u1 can choose a single resource from: {r1, r2, r3}
u2 can choose a single resource from: {r1, r2}
u3 can choose a single resource from: {r1, r4}
u4 can choose a single resource from: {r2}
in this case I should allocate
r3->u1, r1->u2, r4->u3, r2->u4.
If this was allocated differently u4 will have no resource to be allocated.
This is only to explain the problem, I need to solve this for 200 users and 100 resources.
Can I seek your advise on which algorithm to use or how to solve this?

I often solve these type of assignment problems with an LP/MIP solver. The size is not too big so almost any solver will do and there are many readily available. It may look like a bit of overkill but in my experience it offers some useful flexibility (e.g. fixing some assignments, allowing additional ad-hoc constraints).
Your problem could be formulated as:
I solved the problem as an RMIP which is just an LP (the x variables are automatically integer for this type of problem).
In response to your question let me try to explain the equations.
First of all we need to note that the variables x(u,r) only assume the values 0 or 1. This is a property of linear assignment problems. The reason is not totally obvious but a good book on linear programming can tell you more.
The first equation assign1 says: we can assign each user to at most one resource. E.g. for user u1 we have: x(u1,r1)+x(u1,r2)+x(u1,r3) <= 1. This equation forbids that a user is assigned to two or more resources. We allow for unassigned users in case we are short of resources (e.g. if we have a dataset with 2 users and just 1 resource). As a user cannot be assigned to all resources, we do not sum over all r but only over the allowed combinations.
The second equation assign2 says: we can assign each resource to at most one user. E.g. for resource r1 we have: x(u1,r1)+x(u2,r1)+x(u3,r1) <= 1. This equation forbids that a resource is assigned to two or more users. We need this one also otherwise several different users could be assigned to the same resource. We allow for unassigned resources in case we are short of users (e.g. for the case where we have 2 resources and just 1 user). As a resource cannot be assigned to any user, we do not sum over all u but only over the allowed combinations.
Finally the objective counts how many valid assignments were made. This is the value we want to maximize. The trick is again to sum over the allowed combinations to prevent illegal assignments.
The model is a slight variation on the LP model described here. Much more information on the assignment problem can be found in this book.
For your little data set, here is the input data and the results:

I've written a simple assembler that allocates variable to registers. What I found to be most efficient to to do the hardest allocation first, then proceed to do the next hardest.
So in your case, you have a list of users who want an allocation. Since each user has a different rule for the allocation, you need to create a count for each of the available resources.
Then proceed as follows:
using the specific rules, count available resources
select the user with the minimum
in cases of ties, randomally select one
allocate the resource for the selected user
repeat
In this manner, you're giving priority to those users that are hardest to allocate for. But given the users and resources there may not be a solution so you may need to retry several times. If after N tries, no solution is found abort.

Related

Modeling Multiple Depot Vehicle Scheduling Problem in OR-Tools

Is it possible to solve the Multiple Depot Vehicle Scheduling Problem (MDVSP) in OR-tools?
The problem is detailed in this paper, but here is a brief summary.
We are given a set of depots and the number of available vehicles at each. We are given a set of timetabled trips, and we know the origin, destination, start time, end time, and a set of depots that can serve a given trip. While connecting two trips, that is assigning a vehicle to serve for two trips sequentially, there may be an unoccupied travel, so called a dead-head trip. There are also dead-heads while going from a depot to the first trip and returning from the last trip to a depot. The objective is to minimize the sum of all dead-head trip costs while ensuring each trip is served by exactly one vehicle and the number of vehicles used does not exceed the availability. (Other trips/links, i.e., occupied trips, must in any case need to be served/traversed; so, there is no need to include them in the objective).
Seems you want to take into account the arc cost only if vehicle is empty. (note: fixed typo)
AFAIK, there is no easy way to do it using OR-Tools. In C++ you may use the DimensionDependentDimension and returning the arc cost if a capacity dimension is zero, and zero otherwise...
Also I'm curious why you would like to only count dead-trip e.g. if the overall vehicle route is several time longer with very few dead-trip instead of a shorter route with few dead-trip why would you want to incentive the first one ?
e.g. a route of 100km with 1km dead-trip is two time better than a 50km route with 2km dead-trip...
For multiple depots please take a look at
vrp_starts_ends.py
For TimeWindows: vrp_time_windows.py
Did you take a look at the documentation ?
e.g. https://developers.google.com/optimization/routing/cvrp
using routing.NextVar(A).SetValues([A, B]) you can force the chain A->B
ref: https://github.com/google/or-tools/blob/49b6301e1e1e231d654d79b6032e79809868a70e/ortools/constraint_solver/routing.h#L1364-L1366
note: Solver won't have the possibility to use A->C->B even if is shorter than A->B->C or C->A->B (supposing TW allow both of them...)

Modelling agent behaviour, where single agent operates under two conditions simultaneously

Any tips on how to model agent behaviour in an environment where two sets of rules apply simultaneously.
Specifically, what I am looking to simulate is a situation where an Agent operates under a specific set of rules, such as an employee-employer relationship, but at the same time, operates on perhaps different "informal" rules, such as an employee-employee relationship. Effectively there are two network structures in place, but the agent operates in both structures.
Any example models out there that I could take a look at?
(This is a model design question, not programming, so it probably belongs on the NetLogo user group instead of here.)
My colleague and I wrote a book on modeling decisions that are tradeoffs between competing objectives, in ABMs. It's focus is on ecology but the concepts could be useful for you.
The basic idea is to come up with an objective function that includes both "sets of rules" as you call them. Perhaps something like maximizing your relations with fellow employees without getting fired by the employer. Then build very simple models of how decisions affect the mechanisms that drive co-worker relations, probability of getting fired, etc. It's not simple, but it's very powerful and flexible. You won't find a simple approach that's very general.
The fun part is trying different variations and comparing how they work.
https://press.princeton.edu/books/paperback/9780691195285/modeling-populations-of-adaptive-individuals
Maybe I’m under-thinking this, but..I would encode both (all) sets of rules, and have the agent execute those rules as appropriate.
So, how to choose and execute rules?
Per social interaction:
Execute one behavior randomly based on which relationships are present
Choose one or more behaviors, as #1 and execute all of them in a specific order
As above, but execute behaviors in random order
For all possible behaviors, assign a probability based on whatever factors (number of role-members present, utility, consequence, etc l) Choose and execute one behavior randomly based on that probability (roulettes-wheel selection)
Choose more than one… execute in fixed or random order
Proportionate to the value of a “social-competence” property, Select a number of possible behaviors as #4. Then randomly select one of those to execute.
Here’s a code-segment example of #6
;; list of possible reactions
;; these are variables or reporters that report
;; an anonymous command that executes the behavior
Let action-list (list
boss-action
employee-action
coworker-action
peer-action
)
;; measure social situation
;; list of values from reporters
;; these are reporters that return a value
;; based on, for example, how many of that type of
;; relationship are present.
Let choice-list ( list
( probability-of-doing-boss-behavior )
( probability-of-employee-behavior )
( probability-of-coworker-behavior )
( probability-of-peers-behavior )
)
;; think about situation, choose possible actions,
;; as many times as social-competence allows.
;; roulette-wheel should return the index of the selected action
Let reaction-list (n-values social-competence
[ -> roulette-wheel choice-list ] )
;; choose an action from those options
Let action-index one-of reaction-list
;; execute that action
Run item action-index action-list
The same result as a single combined objective function might be a physics type model where the result of any single set of rules is a vector of some strength pushing ("nudging"?) the agent in some direction. Then you could have as many sets of rules as you want, each contributing it's own vector of force, and the final result would be a resultant combined net force and subsequent Newtonian F=m*a or rearranging acceleration = ( vector sum of forces )/mass.
I'm trying to imagine how I respond when the expectations of different groups I belong to clash, and whether a linear sum vector model describes it. I recall in college when I couldn't resolve Catholic support for the Vietnam War and "Kill for Christ" was a tongue-in-cheek slogan. I think in that case the "forces" didn't cancel out -- they resulted in ABANDONING membership in one of the groups to reduce cognitive dissonance. So, not a linear sum of zero in that case.
Another unstable human approach might be to keep going back and forth when two forces attempting to dominate behavior conflict -- first going with one a few steps then feeling guilty and going the other way a few steps. So which one dominates at any given step might depend on one's recent path and history and which one you "owed" something to. Or imagine being married to two people and trying to keep both of them happy. Maybe you partition space and Monday-Tuesday-Wednesday you keep one happy and Thursday-Friday-Saturday you keep the other happy and Sunday you go fishing.

Are all field of a list belong to one CFS

Do generatable array fields always belong to the same CFS?
In case one of the list fields has a constraint, and another field has a different constraint and they are not connected. Will both the fields belong to the same CFS?
If the fields aren't connected than each field will be on a different CFS.
The question is not totally clear but here is an attempt to answer:
if this is a list of struct with several fields, the different fields will belong to the same CFS only if connected (e.g. l[0].x and l[0].y will belong to the same CFS only if there is a constraint connecting them).
assuming the question referred to different indices of the same list path (e.g. l[0].x and l[1].x, or m[0] and m[1]), then we need to differentiate between the static and runtime considerations:
statically, both paths are considered to belong to the same CFS. For example, ICFS analysis assume that, so "keep x < f(m[0]); keep m[1] < g(x)" will create an ICFS.
on runtime, IntelliGen tries to solve the list items one-by-one (as if they were in different CFSs), for performance reasons. However, when the list items are connected (either directly or to different variables), which in IntelliGen's terms is called 'lace', they are indeed solved as one CFS, which can be very large.
for more details, I suggest to read section 4.3 ("Avoid Dependencies Between List Elements") in the IntelliGen user guide.

consistent hashing on Multiple machines

I've read the article: http://n00tc0d3r.blogspot.com/ about the idea for consistent hashing, but I'm confused about the method on multiple machines.
The basic process is:
Insert
Hash an input long url into a single integer;
Locate a server on the ring and store the key--longUrl on the server;
Compute the shorten url using base conversion (from 10-base to 62-base) and return it to the user.(How does this step work? In a single machine, there is a auto-increased id to calculate for shorten url, but what is the value to calculate for shorten url on multiple machines? There is no auto-increased id.)
Retrieve
Convert the shorten url back to the key using base conversion (from 62-base to 10-base);
Locate the server containing that key and return the longUrl. (And how can we locate the server containing the key?)
I don't see any clear answer on that page for how the author intended it. I think this is basically an exercise for the reader. Here's some ideas:
Implement it as described, with hash-table style collision resolution. That is, when creating the URL, if it already matches something, deal with that in some way. Rehashing or arithmetic transformation (eg, add 1) are both possibilities. This means, naively, a theoretical worst case of having to hit a server n times trying to find an available key.
There's a lot of ways to take that basic idea and smarten it, eg, just search for another available key on the same server, eg, by rehashing iteratively until you find one that's on the server.
Allow servers to talk to each other, and coordinate on the autoincrement id.
This is probably not a great solution, but it might work well in some situations: give each server (or set of servers) separate namespace, eg, the first 16 bits selects a server. On creation, randomly choose one. Then you just need to figure out how you want that namespace to map. The namespaces only really matter for who is allowed to create what IDs, so if you want to add nodes or rebalance later, it is no big deal.
Let me know if you want more elaboration. I think there's a lot of ways that this one could go. It is annoying that the author didn't elaborate on this point; my experience with these sorts of algorithms is that collision resolution and similar problems tend to be at the very heart of a practical implementation of a distributed system.

a simple/practical example of fuzzy c-means algorithm

I am writing my master thesis on the subject of dynamic keystroke authentication. To support ongoing research, I am writing code to test out different methods of feature extraction and feature matching.
My current simple approach just checks if the reference password keycodes matches the currently typed in keycodes and also checks if the keypress times (dwell) and the key-to-key times (flight) are the same as reference times +/- 100ms (tolerance). This is of course very limited and I want to extend it with some sort of fuzzy c-means pattern matching.
For each key the features look like: keycode, dwelltime, flighttime (first flighttime is always 0).
Obviously the keycodes can be taken out of the fuzzy algorithm because they have to be exactly the same.
In this context, how would a practical implementation of fuzzy c-means look like?
Generally, you would do the following:
Determine how many clusters you want (2? "Authentic" and "Fake"?)
Determine what elements you want to cluster (individual keystrokes? login attempts?)
Determine what your feature vectors will look like (dwell time, flight time?)
Determine what distance metric you will be using (how will you measure the distance of each sample from each cluster?)
Create exemplar training data for each cluster type (what does an authentic login look like?)
Run the FCM algorithm on the training data to generate the clusters
To create the membership vector for any given login attempt sample, run it through the FCM algorithm using the clusters you found in step 6
Use the resulting membership vector to determine (based on some threshold criteria) whether the login attempt is authentic
I'm not an expert, but this seems like an odd approach to determining whether a login attempt is authentic or not. I've seen FCM used for pattern recognition (eg. which facial expression am I making?), which makes sense because you're dealing with several categories (eg. happy, sad, angry, etc...) with defining characteristics. In your case, you really only have one category (authentic) with defining characteristics. Non-authentic keystrokes are simply "not like" authentic keystrokes, so they won't cluster.
Perhaps I am missing something?
I don't think you really want to do clustering here. You might want to do some proper fuzzy matching though instead of just allowing some delta on each value.
For clustering, you need to have many data points. Additionally, you'd need to know the proper number of means you need.
But what are these multiple objects meant to be? You have one data point for every keycode. You don't want to have the user type the password 100 times to see if he can do it consistently. And even then, what do you expect the clusters to be? You already know which keycode comes at which position, you don't want to find out what keycodes the user use for his password...
Sorry, I really don't see any clustering here. The term "fuzzy" seems to have mislead you to this clustering algorithm. Try "fuzzy logic" instead.