ANTICHAT.XYZ    VIDEO.ANTICHAT.XYZ    НОВЫЕ СООБЩЕНИЯ    ФОРУМ  
Баннер 1   Баннер 2
Antichat снова доступен.
Форум Antichat (Античат) возвращается и снова открыт для пользователей. Здесь обсуждаются безопасность, программирование, технологии и многое другое. Сообщество снова собирается вместе.
Новый адрес: forum.antichat.xyz
Вернуться   Форум АНТИЧАТ > Оффтоп > Болталка
   
 
 
Опции темы Поиск в этой теме Опции просмотра

Программирование >_<
  #1  
Старый 11.12.2009, 19:35
Аватар для StocKeR
StocKeR
Новичок
Регистрация: 02.09.2007
Сообщений: 17
Провел на форуме:
874730

Репутация: 77
По умолчанию Программирование >_<

Может ктонибудь пожалуйста помочь с дописанием кода для задачи ? :
Создайте алгоритм и разработайте программу для следующего сценария. В файловой системе AFS на клиентских машинах файлы кэшируются целиком. Предположим, что дисковое пространство, выделенное под кэшируемые файлы переполнено. Алгоритм должен решать проблемы при запросе нового файла.

Сырой код есть такой ...

program FileShed;
uses
crt;
const
clients = 5;
MaxCash = 1000;
MaxQueueSize = 10;
MaxProcessedFiles = 100;

type
TFile = record
FileId: integer;
ClientId: integer;
ProcessBegin: integer;
ProcessTime: integer;
size: integer;
end;
TVFiles = array[1..MaxProcessedFiles] of TFile;

TPtr=^TQueue;
Tqueue=record
f: TFile;
next:TPtr;
end;

var
FileId: integer;
IsNewFile: boolean;
ProcessedFiles: integer;
v : TVFiles;
i: longint;
time: integer;
NextFileBirth: integer;
f: TFile;
head, tail: TPtr;

empty, full: boolean;
CurrCash: integer;

var
a,b:TPtr;

procedure message(time: integer; f: TFile; action: integer); forward;

procedure add(var head, tail: TPtr; f:TFile);
var
curr: TPtr;
begin
new(curr);
curr^.f:=f;
curr^.next:=nil;
if head=nil then
head:=curr
else
curr^.next:=tail;
tail:=curr;
end;

procedure del(var head, tail: TPtr; var f: TFile);
var
curr : TPtr;
begin
f := head^.f;
curr := tail;
if curr^.next=nil then
begin
head:=nil;
tail:=nil;
end
else
if curr^.next^.next=nil then
head:=curr
else
repeat
curr:=curr^.next;
until curr^.next^.next=nil;
head:=curr;
head^.next:=nil;
end;

procedure print(q: TPtr);
var
curr:TPtr;
begin
clrscr;
curr:=q;
while curr<>nil do
begin
writeln(curr^.f.fileid, ' ', curr^.f.clientid);
curr:=curr^.next;
end;
readln;
end;

procedure FinishFiles(
var v: TVFiles;
var ProcessedFiles: integer;
CurrTime: integer);
var
i: integer;
begin
if ProcessedFiles > 0 then
for i:= 1 to MaxProcessedFiles do
if (v[i].ProcessBegin + v[i].ProcessTime = CurrTime) then
begin
CurrCash := CurrCash + v[i].size;
message(time, v[i], 2);
v[i].Fileid := 0;
dec(ProcessedFiles);
end;
end;

procedure message(time: integer; f: TFile; action: integer);
var
s: string[10];
begin
case action of
1: s:= 'start';
2: s:= 'finish';
3: s:= 'put in queue';
4: s:= 'refuse';
else
s:= 'unknown';
end;
writeln(time:4, f.fileId:4, f.clientid:4, f.size:4,
f.ProcessBegin:4, f.ProcessTime:4, s);
end;

procedure StartProcess(
f: TFile;
var v: TVFiles;
var CurrCash: integer;
var ProcessedFiles: integer;
CurrTime: integer);
var
i: integer;
begin
i:= 1;
while (i<=MaxProcessedFiles) and (v[i].FileId<>0) do
inc(i);
v[i] := f;
v[i].ProcessBegin := CurrTime;
CurrCash := CurrCash - f.size;
inc(ProcessedFiles);
message(time, v[i], 1);
end;

begin
head := nil;
tail := nil;
time := 0; { начало отсчета }
CurrCash := MaxCash;
FileId := 1;
Randomize;
NextFileBirth := random(10);
ProcessedFiles := 0; { нет файлов }
writeln('time id client size begin total end action');
writeln('========================================= =');
repeat
IsNewFile := false;
if time = NextFileBirth then
begin
NextFileBirth := time + 1+random(9);
f.FileId := FileId;
f.ClientId := 1+random(clients-1);
f.ProcessBegin := 0;
f.ProcessTime := 1+random(9);
f.size := 1+random(99);
IsNewFile := true;
inc(FileId);
end;
if ProcessedFiles>0 then
FinishFiles(v, ProcessedFiles, time);

if not (Empty) then
begin
if CurrCash>=f.size then
StartProcess(f, v, CurrCash, ProcessedFiles, time);
end;

if IsNewFile then
begin
writeln(CurrCash, '->', f.size);
if CurrCash>=f.size then
StartProcess(f,v,CurrCash,ProcessedFiles,time)
else if not(full) then
add(head, tail,f)
else
message(time, f, 4);
{message;}
end;
inc(time);
{write('$');}
delay(50000);
until keypressed;

{
Randomize;
for i:= 1 to 10 do
writeln(i,'->', random(10), '->', random(1000));
}
readln;
end.

{
Задать количество клиентов
Задать минимальный размер файла
Задать размер кэша
Время обработки от 1 до 10 секунд
Время поступления файла с клиента в интервале от 1 до 10 секунд
Установить начало отсчета

Задать массив файлов
номер файла
номер клиента
занимаемое место
время начала обработки
требуемое время
}
 
Ответить с цитированием
 



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Программирование PHP&/MySQL m0Hze О Работе 21 05.06.2010 19:29
Ссылки на сайты и книги по C#, Программирование на C# NeuRonix С/С++, C#, Delphi, .NET, Asm 8 11.12.2009 11:02
Программирование на php Anthon Разное - Покупка, продажа, обмен 0 03.12.2006 09:32
Программирование, как оно есть... Mertvii-Listopad Статьи 0 20.03.2006 01:22



Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT.XYZ