Re: proportionality problem



Digital Puer wrote:
Suppose I have a list of resources, where each resource is
assigned a quality value 1 to 10, inclusive, where 1 is the
highest quality. I want to assign resource requests to each
of these resources in proportion to their quality value.

For example, if I have two resources A and B with quality
values 1 and 4, respectively, I would assign requests to
A and B with a 4:1 ratio because A has 4x the value of B.

How can I extend this to the general case with multiple
resources? For example, if A, B, and C have values 1, 2,
3, how would requests be assigned to A, B, and C? I think
it would be 6:3:2. What's a good way to compute this?


Doing a different class depending on what resource it is, makes for an extensibility headache, but either way you're gonna need a list (or deque) for every type from which it is to be fetched separately. (Could probably be autoextensibly done by getting creative with arrays/vectors, all-representative class/base classes/any/variant, etc.)
If you're fetching by quality not by resource (if A and B are both quality 1, C is 2, then 112 (==ABC) instead of ABABC) then you could create a container as below for each quality instead of each resource.

(If you have a unified "request" class, then you just have to sort them in by which resource they're requesting.)

// Doing this in C++. Exchange the standard library container
// (std::deque<> - double ended queue) to get normal C.

// Defined somewhere
std::deque<Arequest> A;
const int Aquality = 1; // or static int calculated on something
std::deque<Brequest> B;
const int Bquality = 2;
std::deque<Crequest> C;
const int Cquality = 3;

// In a function, probably somewhere else
for (int i=1; i<=10; i++) {
if (! Aquality%i && !A.empty()) A.pop_front().AcceptRequest());
if (! Bquality%i && !B.empty()) B.pop_front().AcceptRequest());
if (! Cquality%i && !C.empty()) C.pop_front().AcceptRequest());
}



PS. I think maybe quality may be a bad choice of words. Perhaps (borrowing from tcp/ip) "metric" would be a better word?
Also, I haven't tried to compile above code, but I expect it will work anyway.
.



Relevant Pages

  • Re: proportionality problem
    ... assigned a quality value 1 to 10, inclusive, where 1 is the ... I want to assign resource requests to each ... Each resource has specific limitations that determine the ... the limitation of the highest quality resource, ...
    (comp.programming)
  • Re: The New Roadmap
    ... It rarely speeds a project ... According to the project management theory the time is _always_ one of the most important resources. ... Also, changing a resource by quantity and/or quality IT surely can consist a supplement to another resource, even this cannot grow to. ...
    (borland.public.delphi.non-technical)
  • Re: Fecking BC ! Fecking iPlayer !!!
    ... Think just what an amazing resource something like iPlayer really is. ... For God sake Col, we all had a VCR 10 years ago that recorded in better quality than BBCi, allowed you to keep the programme forever and didn't tie up a huge amount of Internet resources. ...
    (uk.media.tv.misc)
  • Re: apply SPI CPI to measure Resource
    ... Do you have any experience or think it is workable to use SPI & CPI to ... ACWP for resource, and we also could customerize the some field to ... sort of quality factor needs to be included to make it work. ...
    (microsoft.public.project)
  • Re: Access Log reports -- Top entry and Exit pages
    ... > list of all the entry and exit pages, each of which definitely will be ... > first accessed any resource and last accessed a resource? ... # IP to hostnames hostnames ... # Some spurious http:// requests - to investiagte ...
    (comp.lang.perl.misc)