<jupyter_start><jupyter_text>FDA for Task Offloading<jupyter_code>import mec
import fda
import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Make InfraSelect underlying Infrastructure (infra_1, infra_2, infra_3, infra_4)*Contains server information - Data Rate, Data Energy, Task Rate, Task Energy*<jupyter_code>infra = mec.infra_1()
print('INFRA:\n',infra.render())<jupyter_output>INFRA:
 E,C,A: 1,1,3
VR:[0.22222222 0.2        0.1       ]
VE:[0.56 0.52 0.55]
DE:[0.56 0.52 0.55]
DR:
[[0.         0.2        0.20333333]
 [0.2        0.         0.00333333]
 [0.20333333 0.00333333 0.        ]]<jupyter_text>Make Workflowcreate a workflow object that contains tasks to be placed accross servers<jupyter_code>nT = 5  # number of tasks per workflow
wf = mec.WORKFLOW(nT) # a new workflow is randomly generated when initializing class
print(wf.render())<jupyter_output>V:[ 0.         55.87658814 45.87677561 48.02684339 19.98422136 47.21313421]
D:[90.41298882 78.24669362 72.64021541 51.85202947 60.93641471  2.41404391]<jupyter_text>* New WorkflowGenerate a new workflow which requires to be solved by FDA*Can generate workflow manually by assigning values to wf.V and wf.D*<jupyter_code>wf.new_flow()
print(wf.render())<jupyter_output>V:[ 0.         13.82498439 26.11675291 29.69494886 10.66112951 45.22066629]
D:[84.46885544 87.42179088 61.84794844 85.76350259 12.52546166 15.14467499]<jupyter_text>BaselinesA baseline to compute efficiency. *see mec.py for definition of efficiency*<jupyter_code>bl = mec.BASELINE()
print(bl.total_pies(infra,wf))<jupyter_output>243<jupyter_text>compute baselinesactually compute baselines (if soultion space is small)<jupyter_code>bl.allpie(infra, wf,verbose=0)
bl.render()<jupyter_output>TOTAL-POLICIES: 243

MIN-Cost: 417.3129918761391
MIN-Cost COUNT: 1
[ 202 ] [1 1 1 1 2]

MAX-Cost: 488.86226564221823
MAX-Cost COUNT: 1
[ 101 ] [2 0 2 0 1]<jupyter_text>Fitness Function* Define a fitness function * Define flow2sol() function that can convert solutions from an bounded real space to finite discrete space<jupyter_code>def flow2sol(x):
    return [ int(abs(i)) % infra.A for i in x ]

def fitness(x):
    return mec.COST(infra, wf, flow2sol(x))<jupyter_output><empty_output><jupyter_text>FDA AgorithmInitialize the FDA class<jupyter_code>F = fda.FDA(wf.T, 0, infra.A, fitness, alpha=6, beta=4)<jupyter_output><empty_output><jupyter_text>FDA SoultionsOptimize using FDA<jupyter_code>best_flow, best_flow_cost, Flow_X, Flow_fitness, W_var_history, C_history, V_history  = F.optimize(200, verbose=2)
bes_solution = flow2sol(best_flow)

print('Best Soultion:', flow2sol(best_flow))
print('Cost/Fitness:', best_flow_cost)
print('Efficiency:', 100*bl.geteff(best_flow_cost))<jupyter_output>Initial flow:
 [0.86993234 2.68667679 1.73080759 0.51056533 2.98465085]
[0.36778398 1.49369605 2.14508169 1.48001672 1.74351416]
[0.8259946  2.08108823 0.2134898  2.9518817  1.17690003]
[1.04343779 0.30855625 1.90518965 0.1011147  0.69114091]
[2.86184446 0.2145704  2.73233657 0.52230173 2.29542346]
[0.38224162 0.11710813 1.27459783 2.85854642 2.07963501]


Begin 200 Iterations...
[ITER 1]
best-flow: [0.38224162 0.11710813 1.27459783 2.85854642 2.07963501]  cost: 430.56700622160804
[ITER 2]
best-flow: [ 0.00309952 -1.56091445  2.18120743  2.77880085  2.85093085]  cost: 430.35592132936677
[ITER 3]
best-flow: [ 0.00309952 -1.56091445  2.18120743  2.77880085  2.85093085]  cost: 430.35592132936677
[ITER 4]
best-flow: [ 0.00309952 -1.56091445  2.18120743  2.77880085  2.85093085]  cost: 430.35592132936677
[ITER 5]
best-flow: [ 1.50470161 -1.66712887  2.48755115  2.32976682  2.79176399]  cost: 422.0294871384209
[ITER 6]
best-flow: [ 1.45806842 -1.66383031  2.47803745  2.34371185  2.79360146] [...]<jupyter_text>Custom SoultionTo compare with other soultions<jupyter_code>my_solution = F.get_random_flow()
my_cost = fitness(my_solution)
print('Soultion:', flow2sol(my_solution))
print('Cost/Fitness:', my_cost)
print('Efficiency:', 100*bl.geteff(my_cost))<jupyter_output>Soultion: [0, 2, 2, 2, 0]
Cost/Fitness: 438.81439192209757
Efficiency: 69.94882140068334
{'fraction_non_alphanumeric': 0.12018415313787255, 'fraction_numerical': 0.2536951780954689, 'mean_word_length': 5.264036418816389, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '399565', 'license': 'MIT', 'n_tokens_mistral': 2379, 'n_tokens_neox': 1711, 'n_words': 359, 'path': 'FDA_task_offloading.ipynb', 'repo_name': 'Nelson-iitp/FDATO', 'size': '4127'}