Question: Banker's Algoritmas Programlama devi 1 - A a da detaylar verilen input.json dosyas na g re Banker's Algoritmas n al t racak ve sonucu k

Banker's Algoritmas Programlama devi
1- Aada detaylar verilen input.json dosyasna gre Banker's Algoritmasnaltracak ve sonucu k dosyas olan output.json dosyasna yazacaktr.
2- input.json, Dockerfile, deve ait kaynak kod dosyalarn barndran ogrenciNo.zip dosyas yklenmelidir. Mutlaka zip dosyas olmaldr, dier dosya trleri kabul edilmeyecektir.
3- herhangi bir programlama dilini kullanabilirsiniz. buna gre uygun ekilde Dockerfile dosyas oluturulmaldr.
4-deviniz aadaki ekilde kontrol edilecektir. Herhangi bir hata olmamaldr.
unzip -o ogrenciNo.zip -d osOdev1
cd osOdev1
docker build -t odevkontrol .
docker run --rm -v "$(pwd):/app" odevkontrol
not: Windows iletim sisteminde cmd kullanlrsa yukardaki $(pwd) yerine %cd% kullanlmaldr. powershell iin ise $(Get-Location) kullanlabilir.
son komutun ardrdan output.json dosyas uygun ekilde olumu olmaldr. output.json dosyas ierii incelenerek deerlendirme notunuz belirlenecektir. input.json olacak test verileri paylalmayacaktr.
giri dosyas "input.json".
nproc: processsor says
nres: resource says
allocationMatrix: satrlar prosessor, stunlar srasyla resource olarak belirtilmitir. Processor'larn halihazrda kulland resource saysn gstermektedir.
maximumMatrix: satrlar processor, stunlar resource olarak belirtilmitir. processorlarn maksimum resource taleplerini ifade etmektedir.
availableResources: an itibar ile bota olan resource saysn gstermektedir.
{
"nproc":5,
"nres":3,
"allocationMatrix": [
[0,1,0],
[2,0,0],
[3,0,2],
[2,1,1],
[0,0,2]
],
"maximumMatrix": [
[7,5,3],
[3,2,2],
[9,0,2],
[2,2,2],
[4,3,3]
],
"availableResources":[3,3,2]
}
k dosyas "output.json"
{
"ogrenciNo":24213200,
"safe":"1",
"sonuc": [1,3,4,0,2]
}
sistem safe durumunda ise sonu1, unsafe ise sonu0 olacak.
Safe durumunda ise sonu processor numaralar olarak listede olmal, unsafe durumunda sonu[] olmaldr.
Dockerfile altrmak iin referans olmas asndan aada rnek bir uygulama verilmitir.
rnek Dockerfile dosyas ierii
FROM python:3.9-slim
WORKDIR /app
COPY input.json /app/input.json
COPY test.py /app/test.py
CMD ["python", "test.py"]
rnek test.py dosya ierii:
import json
# Snf tanm
class ResourceManager:
def __init__(self, nproc, nres, allocation_matrix, maximum_matrix, available_resources):
self.nproc = nproc
self.nres = nres
self.allocation_matrix = allocation_matrix
self.maximum_matrix = maximum_matrix
self.available_resources = available_resources
def display_info(self):
print("Number of Processes:", self.nproc)
print("Number of Resources:", self.nres)
print("
Allocation Matrix:")
for row in self.allocation_matrix:
print(row)
print("
Maximum Matrix:")
for row in self.maximum_matrix:
print(row)
print("
Available Resources:")
print(self.available_resources)
def save_available_resources(self, output_file):
# Available resources verisini JSON olarak kaydet
with open(output_file, "w") as file:
json.dump({"availableResources": self.available_resources}, file, indent=4)
print(f"Available resources saved to {output_file}")
# JSON dosyasn oku
with open("input.json", "r") as file:
data = json.load(file)
# Snf rneini olutur
resource_manager = ResourceManager(
nproc=data["nproc"],
nres=data["nres"],
allocation_matrix=data["allocationMatrix"],
maximum_matrix=data["maximumMatrix"],
available_resources=data["availableResources"]
)
# Bilgileri ekrana yazdr
resource_manager.display_info()
# Available resources deerini output.json olarak kaydet
resource_manager.save_available_resources("output.json")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!