Copy and Paste  -   An Application to Copy/Paste Text  

 
S.No 5655 Name code Date/Time 01-Apr-2023 01:04:03 PM

Copy text from below

import numpy as np

 

# Define the parameters of the caching problem

N = 100    # number of end user devices

M = 10     # number of edge devices

C = 10000  # cache capacity of each edge device in bytes

F = np.random.randint(1, 10, size=(N, M))  # access frequency matrix

S = np.random.randint(100, 1000, size=N)  # content size array

 

# Define the heuristic algorithm to solve the caching optimization problem

def cache_heuristic(N, M, C, F, S):

    # Calculate the popularity score for each content

    P = np.sum(F, axis=0)

 

    # Sort the contents by their popularity scores

    sorted_contents = np.argsort(P)[::-1]

 

    # Initialize the cache of each edge device to be empty

    cache = np.zeros((M, C))

 

    # For each content in the sorted list, starting from the most popular content

    for j in sorted_contents:

        # Check if content j can fit in any of the edge devices' caches

        added_to_cache = False

        for k in range(M):

            if np.sum(cache[k]) + S[j] <= C:

                cache[k][np.argmax(cache[k] == 0)] = S[j] * F[:,j].sum()

                added_to_cache = True

                break

 

        # If content j cannot fit in any of the edge devices' caches, use LRU replacement policy

        if not added_to_cache:

            least_popular_device = np.argmin(P)

            least_popular_content_index = np.argmin(cache[least_popular_device])

            cache[least_popular_device][least_popular_content_index] = S[j] * F[:,j].sum()

 

    # Return the cached contents on each edge device

    cached_contents = []

    for k in range(M):

        cached_contents.append(np.where(cache[k] > 0)[0])

 

    return cached_contents

 

# Call the heuristic algorithm and print the results

cached_contents = cache_heuristic(N, M, C, F, S)

for k in range(M):

    print(f"Edge device {k}: Cached contents {cached_contents[k]}")

 





comments powered by Disqus
NEW ENTRIES
S.No Name Entry Time/Date
5871 Updated Kid 20-Dec-2023 07:09:59 AM
5870 Alpha 18-Dec-2023 10:52:22 PM
5869 code 07-Dec-2023 10:41:02 AM
5868 HMZ1 07-Dec-2023 08:50:55 AM
5867 HMZ 07-Dec-2023 08:41:31 AM
5866 Child New 05-Dec-2023 08:45:17 AM
5865 Danielle Simpson 29-Nov-2023 10:52:32 PM
5864 comp 28-Nov-2023 03:37:04 PM
5863 New Kids 27-Nov-2023 07:07:09 AM
5862 Jdh 24-Nov-2023 08:10:16 PM
5861 111 24-Nov-2023 03:02:22 PM
5860 modal 20-Nov-2023 03:02:57 PM
5859 omar 19-Nov-2023 04:27:23 PM
5858 ss 17-Nov-2023 05:14:03 PM
5857 ARCode 17-Nov-2023 02:55:42 PM
5856 Jarvo 17-Nov-2023 08:28:14 AM
5855 K1Ds Vids 17-Nov-2023 06:55:00 AM
5854 best 16-Nov-2023 07:07:10 PM
5853 matchsummary 16-Nov-2023 06:38:13 PM
5852 findindex 16-Nov-2023 06:30:48 PM
5851 loops 16-Nov-2023 05:44:20 PM
5850 sorting 16-Nov-2023 05:36:34 PM
5849 test 16-Nov-2023 05:06:51 PM
5848 New Sexy 16-Nov-2023 07:13:16 AM
5847 455555555 13-Nov-2023 02:52:30 PM
5846 CSG Med 05-Nov-2023 04:08:52 PM
5845 New Kids 04-Nov-2023 06:45:51 AM
5844 BMP 31-Oct-2023 06:41:06 PM
5843 ab 29-Oct-2023 08:51:02 PM
5842 a 29-Oct-2023 08:44:33 PM

[First] [Prev] 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 [Next] [Last]
 
web counter
web counter


To report any error messages or bugs, or other issues, please send email at: info@pakproject.com