(подпись) (Ф. И. О.)
(подпись) (Ф.
И. О.)
2000 г.
В данном курсовом проекте рассматривается задача о машинном моделировании процесса взаимодействия между
тремя проектировщиками и центральной ЭВМ. Проводится анализ этой системы и формализация ее в терминах Q-схем, а также
приведена программа моделирующего алгоритма и математическое описание системы. Проводится сравнительный анализ аналитического и имитационных методов
исследования.
Введение............................................................................................................................... 5
Основная часть..................................................................................................................... 6
Постановка задачи........................................................................................................... 6
Возможные пути исследования..................................................................................... 6
Этап моделирования....................................................................................................... 7
Разработка Q-схемы системы.................................................................................... 7
Разработка моделирующего алгоритма и машинная реализация......................... 10
Разработку моделирующего алгоритма удобно производить в 2 этапа:
1) разработка укрупненного алгоритма;
2) разработка детального алгоритма.
Укрупненный алгоритм показывает наглядно принцип функционирования модели, скрывая детали конкретной
реализации и взаимодействия отдельных блоков схемы, что помогает увидеть общее направление работы модели.
Детальный алгоритм более глубоко отражает функционирование блоков схемы, в нем более подробно
описываются способы реализации каждого блока схемы.
На рис. 4 изображена укрупненная схема моделирующего алгоритма.
Рис. 4 Укрупненная схема моделирующего алгоритма.
Переходя к описанию детальной схемы моделирующего алгоритма нельзя не остановиться на описании технологии, с
помощью которого реализовывался моделирующий алгоритм.
Для описания элементов схемы использовался объектно-ориентированный подход, основными принципами которого
являются
- объединение в рамках одной структуры данных полей и методов (процедур), оперирующих над ними;
- наследование – порождение новых классов объектов, при этом наследники получают те же поля и
методы, что были объявлены в классе непосредственного предка и его предков;
- полиморфизм – возможность изменения (частичного или полного) методов одноименных с методами
предков (т.н. виртуальные методы).
Благодаря этим принципам объектно-ориентированный подход (ООП) стал одним из наиболее популярных в
настоящее время, т.к. позволяет программисту строить иерархию классов, которая отражает естественную иерархию, объекты реального мира.
Таким образом, в ходе построения моделирующего алгоритма были выстроены следующие классы объектов.
TQSheme – класс схемы. На него возложены основные функции по проведению эксперимента, а именно:
- управлению системным временем
- нахождением порядка опроса элементов в зависимости от структуры схемы
- опросу элементов в каждом цикле
- учету заявок, находящихся в системе
- учету особых состояний, происходящих в системе
Так, например, именно класс TQSheme реализует блоки 2 и 3 укрупненного алгоритма при
помощи своих методов соответственно InitEmulation и Analize, а также блоки 4-7 при помощи метода Emulation. Блок-схемы этих методов
приведены ниже.
Рис. 5 Блок-схема процедуры TQSheme.InitEmulation.
Описание:
- блок 1 – происходит инициализация переменных, необходимых для анализа системы;
- блок 2 – создание объектных списков, необходимых для анализа системы: установление конечных
элементов, установление порядка очередности опроса элементов схемы;
- блок 3 – инициализация списков заявок и событий, подготовка их к предстоящему прогону схемы.
Рис. 6 Блок-схема процедуры TQSheme.Analize.
Описание:
- блок 1 – нахождение порядка опроса элементов с занесением порядковых номеров элементов в массив
порядка опроса FOrder;
- блок 2 – нахождение наименьшего временного интервала, необходимого для анализа схемы по «принципу Dt»
Рис. 7 Блок-схема процедуры TQSheme.Emulation.
Описание:
- блок 1 – процедура инициализации процесса моделирования с установлением начальных значений для
всех переменных;
- блок 2 – вызов процедуры Analize;
- блок 3 – проверка окончания моделирования;
- блок 4 – просмотр всех элементов схемы.
Рис. 8 Блок-схема процедуры TQSheme.Step
Описание:
- блок 1 – процедура изъятия заявок из конечных элементов схемы;
- блок 2 – опрос всех элементов схемы в порядке, указанном в массиве FOrder;
- блок 3 – увеличение системного времени на величину Dt;
Каждый элемент схемы, будь то источник, накопитель или канал, также представлен соответствующим классом (TSource, TAccumulator, TChannel). Однако все классы элементов схемы являются
наследниками одного общего класса TElement, который обеспечивает общую функциональность для всех типов элементов схемы, а
именно:
- содержит информацию о том, из каких элементов схемы заявки поступают на данный элемент;
- содержит так называемый контейнер для заявок;
- определяет общий для всех элементов схемы набор условий для возможности принятия заявок, а также
передачи заявок далее по схеме (с помощью этого реализован механизм клапанов)
- определяет порядок, по которому заявки передаются данному элементу от элементов-источников. (Алгоритм
метода AskForParcels показан на рис. 4. Этот метод вызывается объектом класса TQSheme, которому принадлежит этот элемент на этапе
моделирования перехода заявок).
Классы TSource, TAccumulator, TChannel доопределяют функции своего общего предка TElement для обеспечения более конкретного поведения,
характерного для элементов соответствующего класса.
Рис. 9 Блок-схема процедуры TElement.AskForParcel.
Описание:
- блок 1 – задается цикл по всем источникам для данного элемента;
- блок 2, 3 – функции определения выражений для клапанов, установленные пользователем;
- блок 4 – проверка возможности принятия данным элементом заявки;
- блок 5 – прием заявки;
- блок 6 – отказ заявке в приеме.
Главное окно программы показано на рисунке 10.
Рис. 10 Главное окно программы.
Текст программы.
unit QSheme;
interface
uses Classes, SysUtils, Forms, QSObjs, QSTypes, Utils, ExtCtrls;
const
MaxElementCount = 10000;
type
TQSheme = class
private
FParcelsClass : TParcelsClass;
FStepCount : integer;
FSysPeriod : TCustTime;
FStepPeriod : TCustTime;
FSysTime : TCustTime;
FElements : TList;
FFinishElements : TList;
FLastElements : TList;
FSourceElements : TList;
FParcels : TList;
FOrderElementCount : integer;
FEventQueue : TList;
FOrder : array [0..MaxElementCount-1] of integer;
FDiagram : TPaintBox;
protected
function GetElement(Index : integer): TElement;
function GetElementCount: integer;
procedure InitAnalize;
procedure FreeAnalize;
procedure InitEmulation;
procedure FreeEmulation;
procedure FindFinishElements;
procedure GetRecipientsOrder;
procedure Step;
procedure TakeParcelsFromFinishElements;
function IsFinishElement(Element : TElement): Boolean;
function FastestStepPeriod : TCustTime;
procedure ClearParcelList;
procedure ClearEventQueue;
function GetCounts(Index : integer): integer;
function GetParcelCount: integer;
procedure DrawElementLines;
procedure DisplayEvents;
public
function NewParcel: Pointer;
procedure NewEvent(AEvent : integer; ASender, ASource : TObject; AInfo : TInfo);
procedure RedrawDiagram;
procedure Emulation;
procedure Analize;
constructor Create;
destructor Destroy; override;
procedure AddElement(Element : TElement);
procedure GetOrder;
procedure DelElement(Element : TElement);
property SysTime : TCustTime read FSysTime;
property SysPeriod: TCustTime read FSysPeriod write FSysPeriod;
property StepPeriod : TCustTime read FStepPeriod write FStepPeriod;
property Counts[Index : integer]:integer read GetCounts;
property BornParcelCount : integer index 0 read GetCounts;
property StoreParcelCount : integer index 1 read GetCounts;
property WorkParcelCount : integer index 2 read GetCounts;
property PassedParcelCount : integer index 3 read GetCounts;
property RefusedParcelCount : integer index 4 read GetCounts;
property ParcelCount:integer read GetParcelCount;
property StepCount : integer read FStepCount write FStepCount;
property ParcelsClass : TParcelsClass read FParcelsClass write FParcelsClass;
published
property Diagram : TPaintBox read FDiagram write FDiagram;
property ElementCount : integer read GetElementCount;
property Elements[Index : integer] : TElement read GetElement;
end;
implementation
uses MainFrm;
constructor TQSheme.Create;
begin
FElements := TList.Create;
FParcelsClass := TParcel;
FParcels := TList.Create;
FEventQueue := TList.Create;
end;
destructor TQSheme.Destroy;
begin
FElements.Free;
ClearEventQueue;
FEventQueue.Free;
ClearParcelList;
FParcels.Free;
inherited;
end;
function TQSheme.GetElement(Index : integer): TElement;
begin
Result := FElements[Index];
end;
function TQSheme.GetElementCount: integer;
begin
Result := FElements.Count
end;
procedure TQSheme.AddElement(Element: TElement);
begin
if Assigned(Element) then begin
FElements.Add(Element);
Element.Sheme := Self;
end;
end;
procedure TQSheme.DelElement(Element: TElement);
var i,j : integer;
begin
if Assigned(Element) then begin
for i := 0 to ElementCount - 1 do
for j:= Elements[i].SourceCount-1 downto 0 do
if Elements[i].Sources[j] = Element then
Elements[i].DelSource(Element);
FElements.Remove(Element);
end;
end;
function TQSheme.IsFinishElement(Element: TElement):Boolean;
var j,s : integer;
begin
Result := False;
for j := 0 to ElementCount-1 do begin
for s := 0 to Elements[j].SourceCount-1 do begin
if Element = Elements[j].Sources[s] then Exit;
end;
end;
Result := True;
end;
procedure TQSheme.FindFinishElements;
var i : integer;
begin
for i := 0 to ElementCount-1 do
if IsFinishElement(Elements[i]) then begin
FFinishElements.Add(Elements[i]);
FLastElements.Add(Elements[i]);
end;
end;
function TQSheme.FastestStepPeriod: TCustTime;
var i : integer;
Min : TCustTime;
begin
Min := FSysPeriod;
for i := 0 to ElementCount-1 do
if (Elements[i] is TShop) then
with TShop(Elements[i]).Generator do
if Mean-Disp < Min then Min := Mean-Disp;
{$ifndef Precision}
Result := Min;
{$else}
Result := Min div 10;
{$endif}
end;
procedure TQSheme.InitAnalize;
begin
FSysTime := 0;
FStepCount := 0;
FOrderElementCount := 0;
FLastElements := TList.Create;
FSourceElements := TList.Create;
end;
procedure TQSheme.FreeAnalize;
begin
FLastElements.Free;
FSourceElements.Free;
end;
procedure TQSheme.GetRecipientsOrder;
var i,s : integer;
LastElement : TElement;
begin
if FLastElements.Count = 0 then Exit;
for i := 0 to FLastElements.Count-1 do begin
LastElement := TElement(FLastElements[i]);
FOrder[FOrderElementCount] := FElements.IndexOf(LastElement);
Inc(FOrderElementCount);
for s := 0 to LastElement.SourceCount - 1 do
if FSourceElements.IndexOf(LastElement.Sources[s])<0 then
FSourceElements.Add(LastElement.Sources[s]);
end;
SwapPointers(Pointer(FSourceElements),Pointer(FLastElements));
FSourceElements.Clear;
GetRecipientsOrder;
end;
procedure TQSheme.GetOrder;
begin
FindFinishElements;
GetRecipientsOrder;
end;
procedure TQSheme.TakeParcelsFromFinishElements;
var i : integer;
Parcel : TParcel;
begin
for i := 0 to FFinishElements.Count-1 do
with TElement(FFinishElements[i]) do
if CanDrop then begin
Parcel := Container;
NewEvent(EV_PASS,nil,FFinishElements[i],Parcel.Info);
DoBeforeDrop(FFinishElements[i]);
DropParcel;
DoAfterDrop(FFinishElements[i]);
Parcel.State := psPassed;
end;
end;
procedure TQSheme.Step;
var i : integer;
begin
TakeParcelsFromFinishElements;
for i := 0 to FOrderElementCount-1 do Elements[FOrder[i]].AskForParcel;
Form1.Gauge1.Progress := Round(FSysTime/FSysPeriod*100);
Inc(FSysTime,FStepPeriod);
Inc(FStepCount);
end;
procedure TQSheme.Analize;
begin
try
try
InitAnalize;
GetOrder;
FStepPeriod := FastestStepPeriod;
finally
FreeAnalize;
end;
except
on EInvalidPointer do raise;
end;
end;
procedure TQSheme.ClearEventQueue;
var i : integer;
begin
if Assigned(FEventQueue) then begin
for i := 0 to FEventQueue.Count - 1 do FreeMem(FEventQueue[i],SizeOf(TEventRec));
FEventQueue.Clear;
end;
end;
procedure TQSheme.ClearParcelList;
var i : integer;
begin
if Assigned(FParcels) then begin
for i := 0 to FParcels.Count - 1 do TParcel(FParcels[i]).Free;
FParcels.Clear;
end;
end;
procedure TQSheme.InitEmulation;
var i : integer;
begin
ClearParcelList;
ClearEventQueue;
for i := 0 to ElementCount - 1 do
Elements[i].ClearContainer;
FFinishElements := TList.Create;
end;
procedure TQSheme.FreeEmulation;
begin
FFinishElements.Free;
end;
procedure TQSheme.Emulation;
begin
try
InitEmulation;
Analize;
while FSysTime < FSysPeriod do Step;
Form1.Gauge1.Progress := 100;
//RedrawDiagram;
finally
FreeEmulation;
end;
end;
function TQSheme.NewParcel: Pointer;
var P : Pointer;
begin
P := FParcelsClass.Create;
FParcels.Add(P);
Result := P;
end;
procedure TQSheme.NewEvent(AEvent : Integer; ASender, ASource: TObject; AInfo : TInfo);
var P : PEventRec;
begin
GetMem(P,SizeOf(TEventRec));
with P^ do begin
Event := AEvent;
Sender := ASender;
Source := ASource;
Info := AInfo;
SysTime := FSysTime;
end;
FEventQueue.Add(P);
end;
function TQSheme.GetCounts(Index : integer): integer;
var i : integer;
begin
Result := 0;
for i := 0 to FParcels.Count-1 do
if Ord(TParcel(FParcels[i]).State) = Index then Inc(Result);
end;
function TQSheme.GetParcelCount: integer;
begin
Result := FParcels.Count;
end;
const //DrawConstants
Top = 20;
Left = 20;
Interval = 20;
procedure TQSheme.DrawElementLines;
var i : integer;
Y : integer;
begin
for i := 0 to ElementCount-1 do begin
Y :=Top + interval *i;
with Diagram.Canvas do begin
TextOut(0,Y + Font.Height,Elements[i].Name);
MoveTo(0,Y);
LineTo(Diagram.ClientWidth,Y)
end;
end;
end;
procedure TQSheme.DisplayEvents;
{var i : integer;
s : string;}
begin
{Form1.mResults.Items.Clear;
for i := 0 to FEventQueue.Count - 1 do begin
with TEventRec(FEventQueue[i]^) do begin
case Event of
EV_TAKE: S := '+++:';
EV_REFUSE: S := '------:';
EV_PASS: S := 'PASS:';
end;
S := S + IntToStr(Info);
S := S + '['+IntToStr(SysTime)+ '] ';
if Assigned(Source) then S := S + TElement(Source).Name
else S := S+'nil';
S := S + '->';
if Assigned(Sender) then S := S + TElement(Sender).Name
else S := S+'nil';
end;
Form1.mResults.Items.Add(S);
end;}
end;
procedure TQSheme.RedrawDiagram;
//var i : integer;
begin
//Diagram.Canvas.FillRect(Rect(0,0,Diagram.Width,Diagram.Height));
//DrawElementLines;
DisplayEvents;
end;
initialization
Randomize;
end.
unit QSObjs;
interface
uses Classes,QSTypes,SysUtils, Utils;
type
TElement = class;
TIsRightElement = function(Element : TElement): Boolean of object;//far;
TBeforeAfterAction = procedure (Sender : TElement) of object;
TElement = class
private
FId : integer;
FName : string;
FSources : TList;
FSheme : TObject;
FContainer : TParcel;
FOnSourceValidate : TIsRightElement;
FOnDestinationValidate : TIsRightElement;
FBeforeTake: TBeforeAfterAction;
FAfterTake: TBeforeAfterAction;
FBeforeDrop: TBeforeAfterAction;
FAfterDrop: TBeforeAfterAction;
procedure SetSheme(ASheme : TObject);
function GetSourceCount: integer;
function GetSource(Index : integer): TElement;
function GetParcelPresent: Boolean;
function GetCanDropParcelFor(Destination : TElement): Boolean;
function GetCanTakeParcelFrom(Source: TElement): Boolean;
procedure Pass(SourceIndex : integer); virtual;
protected
function GetCanTake: Boolean; virtual; abstract;
function GetCanDrop : Boolean; virtual; abstract;
public
constructor Create;virtual;
destructor Destroy; override;
procedure AddSource(Element : TElement);
procedure DelSource(Element : TElement);
procedure AskForParcel; virtual;
procedure ClearContainer; virtual;
procedure RefuseParcel(SourceIndex : integer);
procedure DropParcel;virtual;
procedure TakeParcel(SourceIndex : integer); virtual;
procedure DoBeforeDrop(Sender : TElement);
procedure DoBeforeTake(Sender : TElement);
procedure DoAfterDrop(Sender : TElement);
procedure DoAfterTake(Sender : TElement);
property CanDropParcelFor[Destination : TElement]: Boolean read GetCanDropParcelFor;
property CanTakeParcelFrom[Source : TElement]: Boolean read GetCanTakeParcelFrom;
property Container : TParcel read FContainer write FContainer;
property ParcelPresent : Boolean read GetParcelPresent;
property CanTake : Boolean read GetCanTake;
property CanDrop : Boolean read GetCanDrop;
property Id: integer read FId write FId;
published
property Name : string read FName write FName;
property Sheme: TObject read FSheme write SetSheme;
property SourceCount : integer read GetSourceCount;
property Sources[Index : integer]: TElement read GetSource;
property OnSourceValidate : TIsRightElement read FOnSourceValidate write FOnSourceValidate;
property OnDestinationValidate : TIsRightElement read FOnDestinationValidate write FOnDestinationValidate;
property BeforeTake: TBeforeAfterAction read FBeforeTake write FBeforeTake;
property AfterTake: TBeforeAfterAction read FAfterTake write FAfterTake;
property BeforeDrop: TBeforeAfterAction read FBeforeDrop write FBeforeDrop;
property AfterDrop: TBeforeAfterAction read FAfterDrop write FAfterDrop;
end;
TElementClass = class of TElement;
TGenerator = class
private
FMean : TCustTime;
FDisp : TCustTime;
FRandomType : TRandomType;
function GetRandom: TCustTime;
public
constructor Create;
property Mean : TCustTime read FMean write FMean;
property Disp : TCustTime read FDisp write FDisp;
property RandomType : TRandomType read FRandomType write FRandomType;
property Time : TCustTime read GetRandom;
end;
TShop = class(TElement)
private
FGenerator : TGenerator;
FEndWorkTime : TCustTime;
procedure Pass(SourceIndex : integer); override;
function GetProcessed: Boolean;
protected
function GetCanTake : Boolean; override;
function GetCanDrop : Boolean; override;
property EndWorkTime : TCustTime read FEndWorkTime write FEndWorkTime;
public
constructor Create; override;
destructor Destroy;override;
procedure DropParcel; override;
property Generator : TGenerator read FGenerator;
property Processed : Boolean read GetProcessed;
procedure Work; virtual;
end;
TChannel = class(TShop)
public
procedure Pass(SourceIndex : integer); override;
end;
TSource = class(TShop)
private
procedure TakeParcel(SourceIndex: integer);override;
public
procedure Pass(SourceIndex : integer); override;
procedure AskForParcel; override;
end;
TAccumulator = class(TElement)
private
FParcels : TList;
FLimited : Boolean;
FCapacity : integer;
function GetParcel(Index : integer): TParcel;
function GetFreeSpacePresent : Boolean;
function GetEmpty: Boolean;
procedure SetCapacity(Value : integer);
function GetCapacity : integer;
function GetParcelCount : integer;
procedure Pass(SourceIndex : integer); override;
function GetCanTake : Boolean; override;
function GetCanDrop : Boolean; override;
public
constructor Create; override;
destructor Destroy; override;
procedure ClearContainer; override;
procedure DropParcel; override;
property ParcelCount : integer read GetParcelCount;
property Parcels[Index : integer]: TParcel read GetParcel;
property FreeSpacePresent: Boolean read GetFreeSpacePresent;
property Empty : Boolean read GetEmpty;
procedure TakeParcel(Index : integer); override;
published
property Capacity : integer read GetCapacity write SetCapacity;
property Limited : Boolean read FLimited write FLimited;
end;
TAccumulatorClass = class of TAccumulator;
implementation
uses QSheme;
constructor TElement.Create;
begin
FSources := TList.Create;
end;
destructor TElement.Destroy;
begin
FSources.Free;
inherited;
end;
procedure TElement.SetSheme(ASheme : TObject);
begin
if Assigned(ASheme) then FSheme := ASheme;
end;
procedure TElement.AddSource(Element : TElement);
begin
if Assigned(Element) then FSources.Add(Element);
end;
procedure TElement.DelSource(Element: TELement);
begin
if Assigned(Element) then FSources.Remove(Element);
end;
function TElement.GetSourceCount: integer;
begin
Result := FSources.Count;
end;
function TElement.GetSource(Index: integer): TElement;
begin
Result := FSources[Index];
end;
procedure TElement.TakeParcel(SourceIndex : integer);
begin
FContainer := Sources[SourceIndex].FContainer;
TQSheme(Sheme).NewEvent(EV_TAKE,Self,Sources[SourceIndex],FContainer.Info);
Sources[SourceIndex].DropParcel;
end;
procedure TElement.Pass(SourceIndex: integer);
var Source : TElement;
begin
if SourceIndex <> -1 then Source := Sources[SourceIndex];
DoBeforeTake(Self);
if SourceIndex <> -1 then Source.DoBeforeDrop(Source);
TakeParcel(SourceIndex);
DoAfterTake(Self);
if SourceIndex <> -1 then Source.DoAfterDrop(Source);
end;
function TElement.GetCanDropParcelFor(Destination: TElement): Boolean;
begin
Result := CanDrop;
if Assigned(OnDestinationValidate) then
Result := Result and OnDestinationValidate(Destination)
end;
function TElement.GetCanTakeParcelFrom(Source : TElement) : Boolean;
begin
if Assigned(OnSourceValidate) then
Result := OnSourceValidate(Source)
else Result := True;
end;
procedure TElement.AskForParcel;
var i : integer;
Source : TElement;
begin
for i := 0 to SourceCount - 1 do begin
Source := Sources[i];
if Source.CanDropParcelFor[Self] and CanTakeParcelFrom[Source] then
if CanTake then begin
Pass(i);
if Self is TShop then Exit;
end
else
if not (Source is TAccumulator) then RefuseParcel(i);
end;//for
end;
function TElement.GetParcelPresent: Boolean;
begin
Result := FContainer <> nil;
end;
procedure TElement.ClearContainer;
begin
DropParcel;
end;
procedure TElement.RefuseParcel(SourceIndex: integer);
begin
Sources[SourceIndex].Container.State := psRefused;
TQSheme(Sheme).NewEvent(EV_REFUSE,Self,Sources[SourceIndex],Sources[SourceIndex].Container.Info);
Sources[SourceIndex].DropParcel;
end;
procedure TElement.DropParcel;
begin
Container := nil;
end;
procedure TElement.DoBeforeDrop(Sender : TElement);
begin
if Assigned(FBeforeDrop) then FBeforeDrop(Sender);
end;
procedure TElement.DoAfterDrop(Sender : TElement);
begin
if Assigned(FAfterDrop) then FAfterDrop(Sender);
end;
procedure TElement.DoBeforeTake(Sender : TElement);
begin
if Assigned(FBeforeTake) then FBeforeTake(Sender);
end;
procedure TElement.DoAfterTake(Sender : TElement);
begin
if Assigned(FAfterTake) then FAfterTake(Sender);
end;
constructor TGenerator.Create;
begin
inherited;
FRandomType := rtPlane;
end;
function TGenerator.GetRandom: TCustTime;
var R : single;
begin
case FRandomType of
rtPlane: R := PlaneRND;
rtNormal: R := NormRND;
rtExponent: R := ExpRND
else
R := Random;
end;
Result := FMean - FDisp + Round(R * 2 * FDisp);
end;
constructor TShop.Create;
begin
inherited;
FGenerator := TGenerator.Create;
end;
destructor TShop.Destroy;
begin
FGenerator.Free;
inherited;
end;
procedure TShop.DropParcel;
begin
inherited;
FEndWorkTime := 0;
end;
procedure TShop.Pass(SourceIndex : integer);
begin
inherited;
Work;
end;
function TShop.GetProcessed: Boolean;
begin
Result := (TQSheme(Sheme).SysTime >= FEndWorkTime);
end;
function TShop.GetCanTake: Boolean;
begin
Result := not ParcelPresent and Processed;
end;
function TShop.GetCanDrop: Boolean;
begin
Result := ParcelPresent and Processed;
end;
procedure TShop.Work;
begin
FEndWorkTime := TQSheme(Sheme).SysTime + FGenerator.GetRandom;
end;
procedure TChannel.Pass(SourceIndex: integer);
begin
inherited;
Container.State := psWork;
end;
procedure TSource.TakeParcel(SourceIndex: integer);
begin
Container := TQSheme(Sheme).NewParcel;
end;
procedure TSource.Pass(SourceIndex : integer);
begin
inherited;
Container.State := psBorn;
end;
procedure TSource.AskForParcel;
begin
if CanTake then Pass(-1);
end;
constructor TAccumulator.Create;
begin
FLimited := False;
FParcels := TList.Create;
inherited;
end;
destructor TAccumulator.Destroy;
begin
FParcels.Free;
end;
function TAccumulator.GetParcel(Index : integer): TParcel;
begin
Result := FParcels[Index];
end;
function TAccumulator.GetCanDrop: Boolean;
begin
if Empty then AskForParcel;
if not Empty then Container := FParcels.First;
Result := not Empty;
end;
function TAccumulator.GetCanTake: Boolean;
begin
Result := FreeSpacePresent;
end;
function TAccumulator.GetFreeSpacePresent: Boolean;
begin
Result := (Capacity <> FParcels.Count) or (not Limited);
end;
function TAccumulator.GetEmpty: Boolean;
begin
Result := FParcels.Count = 0;
//if not Result then Container := FParcels.First;
end;
procedure TAccumulator.DropParcel;
begin
if not Empty then FParcels.Delete(0);
inherited;
end;
function TAccumulator.GetCapacity : integer;
begin
Result := FCapacity;
end;
function TAccumulator.GetParcelCount: integer;
begin
Result := FParcels.Count;
end;
procedure TAccumulator.SetCapacity(Value : integer);
begin
FLimited := True;
FCapacity := Value;
end;
procedure TAccumulator.ClearContainer;
begin
FParcels.Clear;
inherited;
end;
procedure TAccumulator.Pass(SourceIndex : integer);
begin
inherited;
Container.State := psStore;
end;
procedure TAccumulator.TakeParcel(Index : integer);
begin
FParcels.Add(Sources[Index].Container);
TQSheme(Sheme).NewEvent(EV_TAKE,Self,Sources[Index],Sources[Index].Container.Info);
Container := FParcels.Last;
Sources[Index].DropParcel;
end;
end.