THINK FIRST·CODE LATER

← All labs

Multi-user offloading: best-response dynamics

Problem

Input: edgeGHz rttMs n, then n users name gigacycles fLocalGHz uploadMs.

Local time = cycles / fLocal. If k users offload, the edge capacity is shared equally: remote time = upload + RTT + cycles / (edgeGHz / k) (in ms).

Initially nobody offloads. In rounds, users update one at a time in input order: a user offloads iff its remote time (counting itself among the k offloaders) is strictly smaller than its local time. Print each change: round 1: U1 offloads (remote 55.0 ms vs local 100.0 ms) or … computes locally (…). Stop after a round without changes (at most 100 rounds).

Then print Equilibrium after r rounds: k of n offload, Latencies (ms): U1=edge 95.0, …, U6=local 100.0, Average latency: X ms and If all offload: Y ms; if none offload: Z ms (averages, 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-2-data-1.txt

20 5 6
U1 0.2 2 40
U2 0.2 2 40
U3 0.2 2 40
U4 0.2 2 40
U5 0.2 2 40
U6 0.2 2 40
What your program must print for os13-2-data-1.txt
round 1: U5 offloads (remote 95.0 ms vs local 100.0 ms)
Equilibrium after 2 rounds: 5 of 6 offload
Latencies (ms): U1=edge 95.0, U2=edge 95.0, U3=edge 95.0, U4=edge 95.0, U5=edge 95.0, U6=local 100.0
Average latency: 95.8 ms
If all offload: 105.0 ms; if none offload: 100.0 ms

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-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os13-2-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.