48760 (Реализация на ЭВМ решения задачи оптимальной политики замены оборудования), страница 4
Описание файла
Документ из архива "Реализация на ЭВМ решения задачи оптимальной политики замены оборудования", который расположен в категории "". Всё это находится в предмете "информатика" из 1 семестр, которые можно найти в файловом архиве . Не смотря на прямую связь этого архива с , его также можно найти и в других разделах. Архив можно найти в разделе "курсовые/домашние работы", в предмете "информатика, программирование" в общих файлах.
Онлайн просмотр документа "48760"
Текст 4 страницы из документа "48760"
action : byte;
end;
IVector = record
size : word;
items : array[1..MAX_VECTOR_SIZE - 1] of byte;
end;
DVector = record
size : word;
items : array[0..MAX_VECTOR_SIZE - 1] of real;
end;
var
vectorR : DVector;
vectorU : DVector;
outMatrix : TOutMatrix;
optimalPlan : IVector;
startTime : word;
count : word;
{----------------------------------------------------------------------------}
procedure ReadData(path : string);
var
inFile : Text;
i : word;
elem : real;
s : string;
begin
Assign(inFile, path);
Reset(inFile);
Writeln('Условие:');
repeat
Readln(inFile, s);
Writeln(s);
until (s = '');
Writeln('Начальные данные:');
Write('R(x) : ');
i := 0;
while not Eoln(inFile) do
be
Read(inFile, elem);
Write(elem:3:1, ' ');
vectorR.items[i] := elem;
Inc(i);
end;
vectorR.size := i;
Readln(inFile);
Writeln;
Write('U(x) : ');
i := 0;
while not Eof(inFile) do
begin
Read(inFile, elem);
Write(elem:3:1, ' ');
vectorU.items[i] := elem;
Inc(i);
end;
vectorU.size := i;
Close(inFile);
Writeln;
Write('начальный возраст оборудования = ');
Readln(startTime);
Write('расчетный период = ');
Readln(count);
Writeln;
end;
{----------------------------------------------------------------------------}
procedure WriteData;
var
i : word;
q : array[0..1] of string;
begin
Writeln('Решение:');
q[0] := 'заменить';
q[1] := 'сохранить';
for i := 1 to optimalPlan.size do
Writeln(i, ' year -> ', q[optimalPlan.items[i]]);
end;
{----------------------------------------------------------------------------}
function S(t : word) : real;
begin
S := 2;
end;
{----------------------------------------------------------------------------}
function P(t : word) : real;
begin
P := 15;
end;
{----------------------------------------------------------------------------}
function U(t : word) : real;
begin
U := vectorU.items[t];
end;
{----------------------------------------------------------------------------}
function R(t : word) : real;
begin
R := vectorR.items[t];
end;
{----------------------------------------------------------------------------}
function F(t : word; order: word; var action : byte) : real;
var
a : real;
b : real;
begin
if (order = 1)
then
begin
a := R(t) - U(t);
b := S(t) - P(t) + R(0) - U(0);
if (b >= a)
then
begin
F := b;
action := SELL;
end
else
begin
F := a;
action := SAVE;
end;
exit;
end;
a := R(T) - U(T) + outMatrix.items[order - 1, t + 1].value;
b := S(T) - P(T) + R(0) - U(0) + outMatrix.items[order - 1, 1].value;
if (b >= a)
then
begin
F := b;
action := SELL;
end
else
begin
F := a;
action := SAVE;
end;
end;
{----------------------------------------------------------------------------}
procedure BuildOutMatrix;
var
i : word;
j : word;
action : byte;
begin
outMatrix.rows := vectorR.size - 1;
outMatrix.cols := vectorR.size;
for i := 1 to outMatrix.rows do
for j := 0 to outMatrix.cols do
begin
outMatrix.items[i, j].value := F(j, i, action);
outMatrix.items[i, j].action := action;
end;
end;
{----------------------------------------------------------------------------}
procedure GetOptimalPlan(startTime : word; count : byte);
var
i : word;
currTime : word;
begin
currTime := startTime;
optimalPlan.size := count;
for i := count downto 1 do
begin
optimalPlan.items[count - i + 1] := outMatrix.items[i, currTime].action;
if (outMatrix.items[i, currTime].action = SELL)
then
currTime := 1
else
Inc(currTime);
end;
end;
{----------------------------------------------------------------------------}
begin
ClrScr;
ReadData('data.txt');
BuildOutMatrix;
GetOptimalPlan(startTime, count);
WriteData;
Readln;
end.