THINK FIRST·CODE LATER

← All labs

The offloading decision: local, edge or cloud?

Problem

Input: C D fLocal Pcompute Ptx alpha (C in gigacycles, D in KB with 1 KB = 1,000 bytes, fLocal in GHz, powers in W, alpha ∈ [0, 1]), then two lines name fServer bandwidthMHz snrDb rttMs (edge, then cloud).

Compute the uplink rate R = B log₂(1 + 10^(snr/10)); for each server print edge: uplink 69.2 Mb/s, upload 23.1 ms, compute 10.0 ms, RTT 5.0 ms. Then for local, edge, cloud print %-6s time X ms, energy Y mJ, cost Z (times and energies with 1 decimal, cost with 3), where the phone's remote energy is Ptx × upload time and cost = alpha × time/time_local + (1 − alpha) × energy/energy_local. Then Fastest: …, least energy: …, best weighted (alpha 0.5): … (first one on ties, in the order local, edge, cloud) and for each server Break-even uplink for edge: 18.8 Mb/s or … never faster than local. Numbers are printed as integers when whole, else with 1 decimal.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os13-1-data-1.txt

0.2 200 2 0.9 1.3 0.5
edge 20 20 10 5
cloud 50 20 10 60
What your program must print for os13-1-data-1.txt
edge: uplink 69.2 Mb/s, upload 23.1 ms, compute 10.0 ms, RTT 5.0 ms
cloud: uplink 69.2 Mb/s, upload 23.1 ms, compute 4.0 ms, RTT 60.0 ms
local  time 100.0 ms, energy 90.0 mJ, cost 1.000
edge   time 38.1 ms, energy 30.1 mJ, cost 0.358
cloud  time 87.1 ms, energy 30.1 mJ, cost 0.603
Fastest: edge, least energy: edge, best weighted (alpha 0.5): edge
Break-even uplink for edge: 18.8 Mb/s
Break-even uplink for cloud: 44.4 Mb/s

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os13-1-data-1.txt

Windows PowerShell does not understand <:

Get-Content os13-1-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.