python – Find the sub-list with the best utility function among all the permutations in the list

I have the following problem:
Among the list of items, I need to find the subset with the maximum value of a given utility function.

In addition, the type of fitted element must be different

import system

class object:
def __init __ (self, initial_position, object_type):
self.initial_position = initial_position
self.object_type = object_type

@property
def object_relevance (auto):
& # 39; & # 39; & # 39;
utility object function
& # 39; & # 39; & # 39;
returns 2 ** (- self.initial_position)


ObjectList class:
def __init __ (auto, list):
self.object_list = list
self.rel = 0
self.best_list = []

def _list_relevance (self, object_sub_list):
& # 39; & # 39; & # 39;
list utility function
& # 39; & # 39; & # 39;
relevance = 0
for j in the range (len (object_sub_list)):
relevance + = (2 ** (-j)) * object_sub_list[j].object_relevance
relevance of return

def _check_sub_list_permissibility (self, object_sub_list):
for i in the range (len (object_sub_list) - 1):
if object_sub_list[i].object_type == object_sub_list[i + 1].type of object:
returns False
other:
pass
returns True

def_element_not_exist_in_the_list (self, object_sub_list, elem):
for object in object_sub_list:
if elem.initial_position == object.initial_position:
returns False
returns True

def _traverse (self, object_list, init_list):
for elem in object_list:
try_list = init_list.copy ()
if self._element_not_exist_in_the_list (try_list, elem):
try_list.append (elem)
if self._check_sub_list_permissibility (try_list):
init_list = try_list
if self._list_relevance (init_list)> self.rel:
self.best_list = init_list
self.rel = self._list_relevance (init_list)
next = [object for object in object_list if object.initial_position != elem.initial_position]
                self._traverse (next, init_list)

def find_relevant_subset (auto):
self._traverse (self.object_list, [])
returns self.best_list

if __name__ == __ hand __:
input = sys.stdin.read ()
data = list (map (int, input.split ()))
n, m = data[:2]
    a_list = [Object(i,object_type) for i, object_type in enumerate(data[2:])]object_list = ObjectList (a_list)
best_list = object_list.find_relevant_subset ()
return_format = & # 39; .join ([str(object.initial_position) for object in best_list])
sys.stdout.write (return_format)

The input format:
The first line contains numbers separated by a space not and m. m – is the number of unique types and not is the number of elements.
Then not input lines the type of each element is specified.

10 2
1
1
1
0
0
1
0
1
1
1

The output format: 0 3 1 4 2 6 5
Index of the initial element of the subset with the utility function max.
My algorithm: I tried to represent all possible combinations of the initial list as a tree and perform the DFS taking into account the given constraints.

Although my code works, I do not find it optimal. I guess there is room for improvement in terms of time complexity.

Is there an analogy with twin prime numbers in rational integers among Gaussian and Eisenstein integers?

The twin prime numbers, like (29, 31) and (137, 139) are interesting to study. I have explored the parallels of Gaussian and Eisenstein integers with rational integers. For example, they have prime numbers and composites in common. But are there "twin primes"? There may not be any direct analogy, since the relations> and <are ambiguous in the whole numbers of Gauss and Eisenstein – unless you speak of the norm.

People who do not like Jeremy Kyle is it because you see yourself among his guests?

I do not watch TV and I share the same thing
seen on TV like Madonna my number one actually

From what I can understand, it was really the gutter level
so-called entertainment and what is their accuracy
"lie detectors" which are polygraphic and unreliable?

If he went elsewhere, she was failing him one way or another
but instead of looking at each other to know why now he's dead
and some women are just boring and moody about the sex of the
Couples should not live together, that's where decay sets in.

Be with each other but have your own independent places
own clean bathroom laundry and other private personal space

A vindictive selfish cow who has the conscience for life
and you have that now, it will not come back on the air

He looks a little loose arrogant loose sh / t also he
looks like David Cameron smart a.s.s. with great guardians
big mouth big ideas and not seen or heard since "brexit"

.

Among the bounce rate and exit rate, which is the most important and why?

Bounce Rate: When a visitor lands on your web page and leaves immediately or after a while without visiting any other page, this is called a bounce.
Exit Rate: Every page of your website has an exit rate. It depends on the number of visitors leaving your website via this page. This is independent of the number of pages they viewed on your website before reaching this page.

php – I need to make a customization page, among the components needed to leave a "loose" image where the user can move it up to a certain point

Thank you for your contribution to Stack Overflow in Portuguese!

  • Make sure you respond to the question. Enter the details of your solution and share what you have discovered.

But to avoid

  • Ask for clarification or details about other answers.
  • Make statements based solely on your opinion; point references or previous experiences.

To learn more, read our tips for writing good answers.

[Get] Grant Cardone – Cardone University – Sales Training Ranked Among the Best

See article # 23 for the new DL link:cool:

Hey guys, it's a huge sharing, no groans or authorized complainants – help yourself.

Code:

    cardoneuniversity.com 

Download 100 ways to stay motivated:
Closers Survival Guide
Closing strategies
The 10x rule
If you are not the first, you are the last
Incoming calls
Grant's Inspiration
Prospecting Strategies
Quick solution
Rules of success
Sell ​​or be sold
The basics of selling
The sales process
Theory of the fence
Top Trails of Great Salespeople
Understanding the buyer

Before Trump, were you already aware of the number of racists, ignorant and un-civilized people living among us?

When Obama was elected, this site experienced the strongest racism imaginable. Users such as the Black Bolshevik and President Lawn Jockey have been steadfast in their vile racism, and they are still here under different names.

Trump is only the symptom of a disease that has always existed, a pre-existing condition so to speak. Dishonest racists like Dmitri and homophobes like Librusher have made this site a sewer long before Trump entered his first primary. He simply encourages them to believe that they are normal.

.

combinatorial – Distribute n different objects among r distinct groups so that they all get a maximum of k elements

Thank you for your contribution to Mathematics Stack Exchange!

  • Please make sure to respond to the question. Provide details and share your research!

But to avoid

  • Ask for help, clarification, or answer other answers.
  • Make statements based on opinions; save them with references or personal experience.

Use MathJax to format equations. MathJax reference.

To learn more, read our tips for writing good answers.

plot – 3D Draw a solution among several solutions that satisfies a certain condition

This is a question that follows this post:

Select one of several solutions that meet certain conditions and draw it in 3D with different simulation values.

I was trying to apply the answer to a more complex case I'm working on and I'm getting an error message.

To begin, here is the code of my more complicated function:

1 / (24 (-1 + r) 3 3 r 4 s) (3 d 6 (-3 + 5 r) (-1 + t) + 6 d 5 (3 - 5 r + c (-3) + r (9 - 4 q + 8 (-1 + q) r))) (-1 + t) + 12 d (-1 + r) ^ 3 r ^ 2 (s + 2 t) - 4 (-1 + r) ^ 3 r ^ 2 s ((-1 + r ^ 2) s (-1 + t) + 3 t) + 12 d ^ 3 (-1 + r) r (2 + c (-2 + r) (5 - 2 q + 4 (-1 + q) r)) + s - r (3 + s + rs) + 2 t - 3 rt + (-1 + r + r ^ 2) st) + 3 d 4 (3 + c ^ 2 (1 + 2 (-1 + q) r) (-3 + r (7 - 2 q + 6 (-1 + q) r)) (-1 + t) - 2 c ( -3 + r (9 - 4 q + 8 (-1 + q) r)) (-1 + t) - 3 t + r (3 + 4 r (-5 + 3 r) + 5 t)) + 12 d ^ 2 (-1 + r) r (- (- 1 + c) (s (-1 + t) - 2 t) + r ^ 3 (-1 + c (-1 + q) s (-1 + t) - t) + r ^ 2 (2 + (-1 + c (-1 + 2 q)) s (-1 + t) + (2 + 4c - 4 cq) t) + r (-1 - (1 + c (-2 + q)) s (-1 + t) + (2 - 5 c + 2 cq) t))) = 0

Among the many solutions of $ r $, I would like to select the positive real $ r $ and simulate it with the following simulation values, for example, $ d = $ 0.8, $ s = $ 2, $ t = 0.02 $ and $ 0 <c <1 $ and $ 1 <q <$ 2. J & # 39; would 3DPlot $ r $ against $ c $ and $ q $.

My Mathematica code is:

With[{D=08s=2t=002}ground=solve[{1/(24(-1+r)^^3r4s)(3d^6(-3+5r)(-1+t)+6d^5(3-5r+c(-3+r(9-4q+8(1+q)r)))(-1+t)+12d(-1+r)^^3r2(s+2t)-4(-1+r)^2s^3r((-1+r^2)s(1+t)+3t)+12d^3(-1+r)r(c+2(-2+r(5-2q+4(-1+q)r))+sr(3+s+rs)+2t-3RT+(-1+r+r^2)st)+3d^4(3+c^2(1+2(-1+q)r)(-3+r(7-2q+6(-1+q)r))(-1+t)-2c(-3+r(9-4q+8(1+q)r))(-1+t)+r-3T(34r+(-5+3r)+5t))^2+12d(-1+r)r(-(-1+c)(s(1+t)-2t)+r^3(-1+c(1+q)s(-1+t)t)+r^2(2+(-1+c(-1+2q))s(-1+t)+(2+4c-4cq)t)+r(-1-(1+c(-2+q))s(1+t)+(2-5C2cq+)t)))==00<=c<=11<=q[{D=08s=2t=002}ground=Solve[{1/(24(-1+r)^^3r4s)(3d^6(-3+5r)(-1+t)+6d^5(3-5r+c(-3+r(9-4q+8(1+q)r)))(-1+t)+12d(-1+r)^^3r2(s+2t)-4(-1+r)^2s^3r((-1+r^2)s(1+t)+3t)+12d^3(-1+r)r(c+2(-2+r(5-2q+4(-1+q)r))+sr(3+s+rs)+2t-3RT+(-1+r+r^2)st)+3d^4(3+c^2(1+2(-1+q)r)(-3+r(7-2q+6(-1+q)r))(-1+t)-2c(-3+r(9-4q+8(1+q)r))(-1+t)+r-3T(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r(-1-(1+c(-2+q))s(-1+t)+(2-5c+2cq)t)))==00<=c<=11<=q<= 2}, r, r > 0]]; Plot3D[Evaluate[r /. sol], {c, 0, 1}, {q, 1, 2}]

And once launched, I get a very long warning message, including:

Warning: r> 0 is not a valid domain specification. Assuming that this is a variable to eliminate.

Can someone help? Thank you so much!

Algorithms – Distribute tasks evenly among a set of servers

I need to distribute a set of long-term jobs on a container cluster in ECS. These jobs should essentially open a socket connection with a remote server and start streaming data for import into a database.

For each client, there may be any number of socket connections needed to use different data streams. Creating a new ECS service for each client is not practical as it would also require new ECS task definitions with slightly different configurations, which would ultimately result in the definition of thousands of services / tasks. This approach would quickly become a nightmare of maintenance and monitoring, so I am looking for a simpler solution.

The list of "flows" is relatively static and is stored in a database of documents. Feeds are added only when new customers are registered. My initial idea was to have a fixed number of containers loaded to retrieve the flow configurations from the database. Each container would attempt to acquire a lease for the stream and, if necessary, start the stream and leave it running until the container is killed or the connection is terminated. Each container should periodically check for new streams available in the pool. They should also extend the lease while the feed is running so that the same feed is not pulled by another container. The could to be a condition of competition in which the lease expires before its extension, so I must be careful to always extend the lease.

This solution would work, but there are obvious blocking points. If each container starts at about the same time, there must be a way to control the number of jobs that each container is allowed to start at the same time, so that 1 or 2 containers do not start all jobs at the same time. One solution is to extract a job every two seconds until the pool is empty and all flows are rented. This may create an uneven distribution of tasks, and ramp-up time may take some time before all tasks are removed from the pool and rented. I could also ask the containers to pick up a food and start it, then will take another one. Some containers can start their feeds faster and go for another job before another container can finish starting its feed, resulting in hotspots for containers.

Another approach might use something like a consistent hash. If each container can know the ID of itself and other containers, it can hash the flow configuration ID and determine which container it belongs to. It would distribute jobs more equitably, but I should also periodically check for new foods, for example, if a container was killed and food rental contracts expired.

I've also thought that programming actors, as with Akka, could be exactly intended to solve this problem, but that's not without a significant complexity in implementation.

I am open to any suggestions or any other hole you can insert into my existing proposals!