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
5652 CLIENT 21-Mar-2023 10:14:25 AM
5651 SERVER 21-Mar-2023 10:13:46 AM
5650 repo 18-Mar-2023 05:50:40 PM
5649 MET 17 MAR 17-Mar-2023 12:56:12 PM
5648 MET OL 17 17-Mar-2023 12:55:17 PM
5647 Test 11 Mar1 15-Mar-2023 03:14:56 PM
5646 Test 1 15-Mar-2023 01:01:41 PM
5645 Test 1 14-Mar-2023 12:26:27 PM
5644 MET 14 March 14-Mar-2023 09:42:12 AM
5643 Test 1 13-Mar-2023 12:49:03 PM
5642 Test 2 Mar13 13-Mar-2023 10:02:33 AM
5641 09-Mar-2023 04:23:35 PM
5640 CHILD SEXY 09-Mar-2023 08:09:59 AM
5639 . 08-Mar-2023 05:03:21 PM
5638 07-Mar-2023 02:03:15 PM
5637 MS 07-Mar-2023 11:21:53 AM
5636 SEXY GIRLS 06-Mar-2023 08:35:18 AM
5635 test 1 03-Mar-2023 02:35:15 PM
5634 PHD Mar 3 02-Mar-2023 09:58:42 PM
5633 MET Mar 3 02-Mar-2023 09:58:01 PM
5632 Test12 Mar 3 02-Mar-2023 09:57:18 PM
5631 Test 11 Mar3 02-Mar-2023 09:50:54 PM
5630 Test 8 Mar 3 02-Mar-2023 09:45:38 PM
5629 Test 3 Mar 3 02-Mar-2023 09:39:33 PM
5628 Test 2 Mar 3 02-Mar-2023 09:34:35 PM
5627 Test 1 Mar 3 02-Mar-2023 09:31:07 PM
5626 Test 8 Mar 2 01-Mar-2023 07:58:21 PM
5625 Test 3 Mar 2 01-Mar-2023 07:57:36 PM
5624 Test 2 Mar 2 01-Mar-2023 07:56:55 PM
5623 Test 1 Mar 2 01-Mar-2023 07:56:17 PM

[First] [Prev] 11 | 12 [Next] [Last]
 
web counter
web counter


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