Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13891

Allocating Switch Ports to Users Based on Percentage Shares

$
0
0

I'm working on a problem where I need to distribute ports on network switches among users according to specified percentage shares. Given a total number of switches with varying port capacities (e.g., some switches have 12 ports, others have 48 ports), and a set of users each entitled to a specific percentage of the total ports, how can I programmatically allocate these ports to ensure each user receives their fair share while also considering the sequential nature of port assignments within each switch?

How can I improve the allocation logic to handle rounding errors more effectively?Is there an efficient way to ensure sequential allocation within switches while adhering to percentage shares, especially when dealing with switches of different sizes?

i want it to make it standrise like i said if we have 3 user and 3 switches

                             70%        20%      &      10%

switch 1 have 12 ports say 1 to 8 first user 9 to 11 second user 12 the last user

i want all switchs with 12 ports like this and etc for all switchs

Any suggestions or code examples, particularly in Python, that could help optimize this allocation process would be greatly appreciated.

What I've Tried:

Calculating total ports and determining each user's share based on their percentage.Sequentially allocating ports across switches while tracking allocations to maintain order.

total_ports = 12 + 12 + 48# User percentagesuser_percentages = [70, 20, 10]# Calculate the number of ports for each useruser_ports = [round(total_ports * (percentage / 100)) for percentage in user_percentages]user_ports

this code it round down say we have three switchs first one have 12 ports if we multiply 70% * 12 = 8.4 i dont want fraction because ports dont have fraction and i want to standrise it if we say switch of 12 ports first user takes from 1 to 8 second user takes 9 to 11 third user takes 12 so how can we standrise it and dont play with percentage to much


Viewing all articles
Browse latest Browse all 13891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>