Приложение 4 Листинг программы PPP Switch Simulator, используемой для визуализации процесса моделирования КУ
// файл PPPSimul.cpp - точка входа в приложение
//------------------------------------------------------------------------
#include
#pragma hdrstop
#include
//------------------------------------------------------------------------
USEFORM("mainwnd.cpp", MainWindow);
USEFORM("szwnd.cpp", SizeWindow);
//------------------------------------------------------------------------
int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
{
try
{
Application->Initialize();
Application->MainFormOnTaskBar = true;
Application->CreateForm(______________ Classid(TMainWindow), &MainWindow);
Application->CreateForm(______________ Classid(TSizeWindow), &SizeWindow);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//------------------------------------------------------------------------
// файл MainWnd.h - определение класса основного окна
//------------------------------------------------------------------------
#ifndef mainwndH
#define mainwndH
//------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
//------------------------------------------------------------------------
#include
#include
#include
class TMainWindow : public TForm
{
__published:
// controls
TPanel *SimulPanel;
TPanel *CtrlPanel;
TStatusBar *StatusBar;
TStringGrid *RegMatrGrid;
TStringGrid *InpQueGrid;
TStringGrid *OutputGrid;
TButton *StartButton;
TButton *ResetButton;
TRadioGroup *ModeGroup;
TTimer *Timer;
TTrackBar *SimulSpeedTrackBar;
TLabel *SimulSpeedLabel;
TLabel *PctStrRateLabel;
TTrackBar *PctStrRateTrackBar;
TGroupBox *StatGroupBox;
TMemo *StatMemo;
TLabel *TimeLabel;
TLabel *PhaseLabel;
TLabel *TimeTitleLabel;
TLabel *PhaseTitleLabel;
TEdit *ThresholdEdit;
TLabel *ThresholdLabel;
TButton *SizeButton;
TStringGrid *OutTitleGrid;
TStringGrid *InpTitleGrid;
TLabel *SizeLabel;
TRadioGroup *MethodGroup;
// event handlers
void_____ fastcall StartButtonClick(TObject *Sender);
void_____ fastcall ResetButtonClick(TObject *Sender);
void_____ fastcall PctStrRateTrackBarChange(TObject *Sender);
void_____ fastcall ModeGroupClick(TObject *Sender);
void fastcall TimerTimer(TObject *Sender);
void_____ fastcall SimulSpeedTrackBarChange(TObject *Sender);
void_____ fastcall FormCreate(TObject *Sender);
void_____ fastcall SizeButtonClick(TObject *Sender);
void_____ fastcall RegMatrGridTopLeftChanged(TObject *Sender);
void fastcall InpQueGridTopLeftChanged(TObject *Sender);
void fastcall OutputGridTopLeftChanged(TObject *Sender);
void_____ fastcall ThresholdEditChange(TObject *Sender);
public:
typedef enum sm_t { sm_idle, sm_auto, sm_trace, sm_batch_size, sm_batch_rate } sm_tag; typedef enum stat_t { st_throughput, st_rm_time, st_full_time, st_rm_load, st_pct_col } stat_tag; fastcall TMainWindow(TComponent* Owner);
inline short GetCurSize() const { return __size; }
private:
// simulation-related data & functions
sm_t __simulation_mode;
short __size;
long __time;
long __tick;
long __time_threshold;
short __phase;
long __packets_issued;
long __packets_processed;
long long __sum_ticks_spent;
double __packet_stream_rate;
double __sum_RM_time;
double __throughput;
double __mean_relay_time;
double __mean_reg_matr_relay_time;
long long __sum_RM_load;
double __aver_RM_load;
double __sum_aver_packets_per_col;
double __time_aver_packets_per_col;
short __round_robin_selector;
std::vector______ packets_in_queue;
std::vector_____ routing_dir;
std::vector_____ lock_dir;
std::vector______ packets_processed_row;
std::vector_____ max_i;
std::vector_____ selected_packet_i;
std::vector< std::vector>_____ time_in_matrix;
std::vector_____ max_time_in_matrix;
std ::vector___ throughput_readings;
std ::vector__ mean_RM_time_readings;
std ::vector___ aver_RM_load_readings;
std ::vector__ mean_relay_time_readings;
std::vector__time_aver_pct_col_readings; std::vector< std::deque> __packet_issue_ticks; std::vector< std::vector> __packet_reg_matr_ticks; bool __SimulationStep();
inline bool __RegMatrixEmpty() const;
int __PacketsInRegMatrixRow(short row) const;
int __PacketsInRegMatrixCol(short col) const;
int __PacketsInRegMatrix() const;
bool __RearrangeControls();
void __SaveStat(stat_t stat_kind = st_throughput);
};
//------------------------------------------------------------------------
extern PACKAGE TMainWindow *MainWindow;
//------------------------------------------------------------------------
#endif
// файл MainWnd.cpp - реализация класса основного окна
//------------------------------------------------------------------------
#include
#include
#pragma hdrstop
#include "mainwnd.h"
#include "szwnd.h"
//------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainWindow *MainWindow;
//------------------------------------------------------------------------
_ fastcall TMainWindow::TMainWindow(TComponent* Owner) : TForm(Owner) {
_____ size = 5;
std::vector time_in_matrix_row; std::deque packet_issue_ticks;
std::vector packet_reg_matr_ticks(___ size, 0);
for (short i = 0; i < __size; ++i ) {
_______________ packets_in_queue.push_back(0);
_______________ routing_dir.push_back(0);
_______________ packets_processed_row.push_back(0);
_______________ max_i .push_back(0);
_______________ selected_packet_i.push_back(0);
_______________ lock_dir.push_back(false);
_______________ max_time_in_matrix.push_back(0); time_in_matrix_row.push_back(0);
}
_____ round_robin_selector = 0;
for (short i = 0; i Cells[i][0] = "0";
OutputGrid->Cells[0][i] = "0";
InpTitleGrid->Cells[i][0] = "Q" + IntToStr(i);
OutTitleGrid->Cells[0][i] = "O" + IntToStr(i);
}
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
StatMemo->Lines->Add("");
TGridRect Rect;
Rect.Left = -1;
Rect.Top = -1;
Rect.Right = -1;
Rect.Bottom = -1;
InpQueGrid->Selection = Rect;
InpTitleGrid->Selection = Rect;
OutputGrid->Selection = Rect;
OutTitleGrid->Selection = Rect;
RegMatrGrid->Selection = Rect;
Timer->Interval = 1000 / SimulSpeedTrackBar->Position;
________ packet_stream_rate = PctStrRateTrackBar->Position / double(PctStrRateTrackBar->Max); StatusBar->SimpleText = "Ready";
}
//------------------------------------------------------------------------
void__ fastcall TMainWindow::StartButtonClick(TObject *Sender)
{
SizeButton->Enabled = false;
if (_____ simulation_mode == sm_trace ) {
// trace mode
ResetButton->Enabled = true;
StatusBar->SimpleText = "Tracing...";
if (____________ phase == 1) PhaseLabel->Caption = "LOAD"; else
if ( phase == 2) PhaseLabel->Caption = "ANALYSE"; else PhaseLabel->Caption = "ISSUE"; try {
______________________ SimulationStep();
} catch (std::range_error & e) {
MessageDlg(e.what(), mtError, mbAbortRetryIgnore, 0); Application->Terminate();
return;
}
if (_______________ phase == 1) {
++__time;
TimeLabel->Caption = IntToStr((long long)_____________________ time);
}
if ( phase == 1) phase = 2; else
if ( phase == 2) phase = 3; else phase = 1;
}
else {
// auto mode or batch mode
__phase = 1;
PhaseLabel->Caption = "LOAD";
if ( StartButton->Caption == "START" ) {
// start simulation
ThresholdEdit->Enabled = false;
StartButton->Caption = "STOP"; if (ThresholdEdit->Text != "") {
// get simulation time duration
try {
___________________________________ time_threshold = StrToInt(ThresholdEdit->Text);
} catch (...) {
_ time_threshold = -1;
}
}
if (______________________ simulation_mode == sm_batch_size || simulation_mode == sm_batch_rate) {
__throughput_readings.clear();
__mean_RM_time_readings.clear();
__aver_RM_load_readings.clear();
__mean_relay_time_readings.clear();
__time_aver_pct_col_readings.clear();
__round_robin_selector = 0;
if (__time_threshold ItemIndex = 0; else ResetButton->Enabled = false;
}
Timer->Enabled = true;
StatusBar->SimpleText = "Simulating...";
} else {
// stop simulation Timer->Enabled = false; ResetButton->Enabled = true; StartButton->Caption = "START"; ThresholdEdit->Enabled = true; StatusBar->SimpleText = "Done";
}
}
}
//------------------------------------------------------------------------
void__ fastcall TMainWindow::ResetButtonClick(TObject *Sender)
{
Timer->Enabled = false;
StatMemo->Lines->Strings[0] = "";
StatMemo->Lines->Strings[1] = "";
StatMemo->Lines->Strings[2] = "";
StatMemo->Lines->Strings[3] = "";
StatMemo->Lines->Strings[4] = "";
StatMemo->Lines->Strings[5] = "";
StatMemo->Lines->Strings[6] = "";
__time = 0;
TimeLabel->Caption = IntToStr((long long)_______ time);
________ time_in_matrix.clear();
________ packet_issue_ticks.clear();
________ packet_reg_matr_ticks.clear();
std::vector time_in_matrix_row; std::deque packet_issue_ticks; std::vector packet_reg_matr_ticks( size, 0);
for (short i = 0; i < size; ++i ) time_in_matrix_row.push_back(0);
for (short i = 0; i < size; ++i ) {
InpQueGrid->Cells[i][0] = "0";
__packets_in_queue[i] = 0;
_______________ time_in_matrix.push_back(time_in_matrix_row);
_______________ packet_issue_ticks.push_back(packet_issue_ticks);
_______________ packet_reg_matr_ticks.push_back(packet_reg_matr_ticks); RegMatrGrid->Rows[i]->Clear();
_______________ packets_processed_row[i] = 0;
OutputGrid->Cells[0][i] = "0";
__lock_dir[i] = false; __max_time_in_matrix[i] = 0;
}
__phase = 1;
PhaseLabel->Caption = "LOAD";
__packets_processed = 0L;
__packets_issued = 0L;
__sum_ticks_spent = 0L;
_____ sum_RM_time = 0.0;
_____ sum_RM_load = 0LL;
_____ sum_aver_packets_per_col = 0.0;
_____ round_robin_selector = 0;
StartButton->Enabled = true;
if (__simulation_mode != sm_batch_size && __simulation_mode != sm_batch_rate) { StartButton->Caption = "START";
_______________ time_threshold = -1;
ThresholdEdit->Enabled = true;
ThresholdEdit->Clear();
SizeButton->Enabled = true;
ModeGroup->ItemIndex = 0; StatusBar->SimpleText = "Ready"; __simulation_mode = sm_auto; MethodGroup->ItemIndex = 0;
} randomize();
}
//------------------------------------------------------------------------
void__ fastcall TMainWindow::PctStrRateTrackBarChange(TObject *Sender)
{
_____ packet_stream_rate = PctStrRateTrackBar->Position / double(PctStrRateTrackBar->Max); PctStrRateLabel->Caption = "Packet stream rate (p): " + FloatToStr(_____________________________ packet_stream_rate);
}
//------------------------------------------------------------------------
void__ fastcall TMainWindow::ModeGroupClick(TObject *Sender)
{
if ( ModeGroup->ItemIndex == 1 ) {
// trace mode will be on Timer->Enabled = false; StartButton->Caption = "STEP"; __simulation_mode = sm_trace;
}
else {
// auto or batch mode will be on
if (_______________ simulation_mode == sm_trace) StartButton->Caption = "START";
if ( ModeGroup->ItemIndex == 0 || ThresholdEdit->Text == "" ) { ModeGroup->ItemIndex = 0;
__simulation_mode = sm_auto;
}
else {
if ( ModeGroup->ItemIndex == 2 ) __simulation_mode = sm_batch_size; else __simulation_mode = sm_batch_rate;
}
}
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::TimerTimer(TObject *Sender)
{
// simulation tick
if (__phase == 1) PhaseLabel->Caption = "LOAD"; else
if (__phase == 2) PhaseLabel->Caption = "ANALYSE"; else PhaseLabel->Caption = "ISSUE"; try {
__SimulationStep();
} catch (std::range_error & e) { Timer->Enabled = false; MessageDlg(e.what(), mtError, mbAbortRetryIgnore, 0); Application->Terminate();
return;
}
if (__phase == 1) {
if (__time_threshold > 0) {
if (__time > __time_threshold) {
// stop simulation
Timer->Enabled = false;
if (__simulation_mode == sm_batch_size) {
// batch size mode - set next size
__throughput_readings.push_back(__throughput); SizeButtonClick(Sender);
if (SizeWindow->SizeSpinEdit->MaxValue < __size) {
__SaveStat();
StartButton->Caption = "START"; StartButton->Enabled = false; ResetButton->Enabled = true; SizeButton->Enabled = true; ThresholdEdit->Enabled = true;
}
else Timer->Enabled = true; return;
}
if (__simulation_mode == sm_batch_rate) {
// batch rate mode - set next packets rate
__mean_RM_time_readings.push_back(__mean_reg_matr_relay_time); __aver_RM_load_readings.push_back(__aver_RM_load);
__mean_relay_time_readings.push_back(__mean_relay_time); __time_aver_pct_col_readings.push_back(__time_aver_packets_per_col); __round_robin_selector = 0;
if (PctStrRateTrackBar->Position < PctStrRateTrackBar->Max) { ResetButtonClick(Sender);
PctStrRateTrackBar->Position += 10;
Timer->Enabled = true;
} else {
__SaveStat(st_rm_time);
__SaveStat(st_full_time);
__SaveStat(st_rm_load);
__SaveStat(st_pct_col);
StartButton->Caption = "START"; StartButton->Enabled = false; ResetButton->Enabled = true; SizeButton->Enabled = true; ThresholdEdit->Enabled = true;
}
return;
}
StartButton->Caption = "START"; StartButton->Enabled = false; return;
}
}
++__time;
TimeLabel->Caption = IntToStr((long long)__time);
}
if (__phase == 1) __phase = 2; else
if (__phase == 2) __phase = 3; else __phase = 1;
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::SimulSpeedTrackBarChange(TObject *Sender)
{
Timer->Interval = 1000 / SimulSpeedTrackBar->Position;
SimulSpeedLabel->Caption = "Simulation speed: " + IntToStr(SimulSpeedTrackBar->Position);
}
//------------------------------------------------------------------------
bool TMainWindow::_ SimulationStep() {
if (++__tick < 0)
throw std::range_error("The tick counter has exceeded the maximum possible value");
if ( double x;_____ phase == 1 ) {
std::vector rnd_values;
// the distribution law is Bernoulli for (short i = 0; i < size; ++i ) {
x = double(rand()) / RAND_MAX; if (x < packet_stream_rate) {
// simulate the arrival of packet i + 1
InpQueGrid->Cells[i][0] = IntToStr(++___________________________ packets_in_queue[i]);
++____________________________ packets_issued;
// save the issue tick for the packet
_____________________________ packet_issue_ticks[i].push_back( tick);
}
}
bool reg_matrix_empty = false;
if (MethodGroup->ItemIndex != 1 || (reg_matrix_empty =_____________ RegMatrixEmpty())) {
// calculate packet routing directions for (short i = 0; i < __size; ++i ) if (! lock_dir[i]) routing_dir[i] = random(_______________________________ size);
}
// load packets from the queues to the register matrix
if (MethodGroup->ItemIndex != 1) {
// PPP, PPU, PPRR - no wait until the matrix is empty
for (short i = 0; i 0) {
if (RegMatrGrid->Cells[i][___________________________________ routing_dir[i]] == "") {
RegMatrGrid->Cells[i][_________________________________________ routing_dir[i]] = "PCT";
InpQueGrid->Cells[i][0] = IntToStr(--________________________________________ packets_in_queue[i]);
auto & head_packet_issue_tick = __packet_issue_ticks[i].front();
__packet_reg_matr_ticks[__routing_dir[i]][i] = head_packet_issue_tick;
__________________________________________ packet_issue_ticks[i].pop_front();
_ lock_dir[i] = false;
} else
if (RegMatrGrid->Cells[i][_________________________________ routing_dir[i]] == "PCT") lock_dir[i] = true;
}
}
else {
// PS - wait until the matrix is empty
if (reg_matrix_empty) {
for (short i = 0; i < __size; ++i ) {
if (__packets_in_queue[i] > 0) {
RegMatrGrid->Cells[i][_________________________________________ routing_dir[i]] = "PCT";
InpQueGrid->Cells[i][0] = IntToStr(--_________________________________________ packets_in_queue[i]);
auto & head_packet_issue_tick = __packet_issue_ticks[i].front();
__packet_reg_matr_ticks[__routing_dir[i]][i] = head_packet_issue_tick;
__________________________________________ packet_issue_ticks[i].pop_front();
}
}
}
}
// estimate the speed and the load of the register matrix
if (int packets_count; __time > 0) {
packets_count = __PacketsInRegMatrix();
if (packets_count > 0) {
std::vector packets_in_row;
for (short i = 0; i < __size; ++i )
packets_in_row.push_back(__PacketsInRegMatrixRow(i));
// calculate the average number of ticks required to relay the packets
int max_packets_in_row = *max_element(packetsjn_row.begin(), padketsjn_row.end());
_____________________________ sum_RM_time += max_packets_in_row / (double)packets_count;
__mean_reg_matr_relay_time = __sum_RM_time / __time;
// calculate the average packets per column value
int sum_packets_in_col = 0;
for ( short i = 0; i < __size; ++i ) sum_packets_in_col += __PacketsInRegMatrixCol(i);
__sum_aver_packets_per_col += sum_packets_in_col / (double)__size;
__time_aver_packets_per_col = __sum_aver_packets_per_col / __time;
}
// calculate the average register matrix load
__sum_RM_load += packets_count;
__aver_RM_load = __sum_RM_load / (double)__time;
}
// Update statistic data
StatMemo->Lines->Strings[0] = "Packets issued: " + IntToStr((long long)____________ packets_issued);
StatMemo->Lines->Strings[1] = "Packets processed: " + IntToStr((long long)______ packets_processed);
StatMemo->Lines->Strings[2] = "Throughput: " + FloatToStr(_____________ throughput);
StatMemo->Lines->Strings[3] = "Mean relay ticks: " + FloatToStr(____________ mean_relay_time);
StatMemo->Lines->Strings[4] = "Mean RM time: " + FloatToStr( mean_reg_matr_relay_time);
StatMemo->Lines->Strings[5] = "Mean RM load: " + FloatToStr( aver_RM_load); StatMemo->Lines->Strings[6] = "Pct per col: " + FloatToStr(_______________________________________________________ time_aver_packets_per_col);
return true;
}
if (_____ phase == 2) {
// increment the time spent in the register matrix
for (short k = 0; k ItemIndex < 2) {
// PPP or PS
std ::vector_____________________ max_time_values;
for (short k = 0; k Cells[__max_i[k]][k] != "") RegMatrGrid->Cells[__max_i[k]][k] = "-->";
}
}
else {
// buffered switch + uniformly selected packets or round robin selection for (short k = 0; k < __size; ++k ) {
// determine the number of packets in the row
short packet_count = 0;
for (short i = 0; i < __size; ++i )
if (RegMatrGrid->Cells[i][k] != "") ++packet_count;
__selected_packet_i[k] = -1;
if (packet_count == 0) continue;
// determine which one must be relayed
if (MethodGroup->ItemIndex == 2) {
// random selection
short packed_selected = random(packet_count); for (short i = 0; i < __size; ++i )
if (RegMatrGrid->Cells[i][k] != "") {
if (packed_selected-- == 0) {
__selected_packet_i[k] = i; RegMatrGrid->Cells[i][k] = "-->"; break;
}
}
}
else {
// round robin selection
short i = __round_robin_selector; while (RegMatrGrid->Cells[i][k] == "") { if (++i == __size) i = 0;
}
__selected_packet_i[k] = i; RegMatrGrid->Cells[i][k] = "-->";
}
}
if (++__round_robin_selector == __size) __round_robin_selector = 0;
}
return true;
}
// issue the packets chosen and clear the registers
if (MethodGroup->ItemIndex < 2) {
// PPP or PS
for ( short i = 0; i < __size; ++i ) {
if (RegMatrGrid->Cells[__max_i[i]][i] != "") {
__sum_ticks_spent += (__tick - __packet_reg_matr_ticks[i][__max_i[i]]);
if (__sum_ticks_spent < 0)
throw std::range_error(
"The total tick counter has exceeded the maximum possible value"); RegMatrGrid->Cells[__max_i[i]][i] = "";
__time_in_matrix[i][__max_i[i]] = 0;
OutputGrid->Cells[0][i] = IntToStr(++__packets_processed_row[i]); ++__packets_processed;
}
}
}
else {
// buffered switch + uniformly selected packets or round robin selection
for ( short i = 0; i < __size; ++i ) {
if (__selected_packet_i[i] < 0) continue;
__sum_ticks_spent += (__tick - __packet_reg_matr_ticks[i][__selected_packet_i[i]]); if (__sum_ticks_spent < 0)
throw std::range_error("The total tick counter has exceeded the maximum possible value"); RegMatrGrid->Cells[__selected_packet_i[i]][i] = "";
OutputGrid->Cells[0][i] = IntToStr(++__packets_processed_row[i]); ++__packets_processed;
}
}
// update statistic data
if (__packets_issued != 0)
__throughput = __packets_processed / double(__packets_issued);
if (__packets_processed != 0)
__mean_relay_time = (__sum_ticks_spent / double(__packets_processed) + 1);
StatMemo->Lines->Strings[1] = "Packets processed: " + IntToStr((long long)__packets_processed);
StatMemo->Lines->Strings[2] = "Throughput: " + FloatToStr(___ throughput);
StatMemo->Lines->Strings[3] = "Mean relay ticks: " + FloatToStr(__ mean_relay_time);
return true;
}
//------------------------------------------------------------------------
void TMainWindow::__SaveStat(stat_t stat_kind)
{
if (stat_kind == st_throughput) {
FILE * stat_file = fopen("throughput.stt", "a+");
for (auto & entry: __throughput_readings ) fprintf(stat_file, "%1.10lf\t", entry); fprintf(stat_file, "\n");
fclose(stat_file);
return;
}
if (stat_kind == st_rm_time) {
FILE * stat_file = fopen("rm_time.stt", "a+");
for (auto & entry: __mean_RM_time_readings ) fprintf(stat_file, "%1.10lf\t", entry); fprintf(stat_file, "\n");
fclose(stat_file);
return;
}
if (stat_kind == st_full_time) {
FILE * stat_file = fopen("full_time.stt", "a+");
for (auto & entry: __mean_relay_time_readings )
fprintf(stat_file, "%1.10lf\t", entry/3.0); // measured in time slots if divided by 3.0 fprintf(stat_file, "\n");
fclose(stat_file);
return;
}
if (stat_kind == st_rm_load) {
FILE * stat_file = fopen("rm_load.stt", "a+");
for (auto & entry:_______________ aver_RM_load_readings ) fprintf(stat_file, "%1.10lf\t", entry);
fprintf(stat_file, "\n");
fclose(stat_file);
return;
}
if (stat_kind == st_pct_col) {
FILE * stat_file = fopen("pct_col.stt", "a+");
for (auto & entry:_______________ time_aver_pct_col_readings ) fprintf(stat_file, "%1.10lf\t", entry);
fprintf(stat_file, "\n");
fclose(stat_file);
return;
}
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::SizeButtonClick(TObject *Sender)
{
if (_____ simulation_mode != sm_batch_size) SizeWindow->ShowModal();
if (__simulation_mode == sm_batch_size || SizeWindow->NewSizeSet()) {
// the number of input/output terminals n has changed
if (__simulation_mode == sm_batch_size) {
++__size;
if (SizeWindow->SizeSpinEdit->MaxValue < size) return;
}
else __size = SizeWindow->GetNewSize();
SizeLabel->Caption = IntToStr(__size) + " x " + IntToStr(__size);
InpTitleGrid->Rows[0]->Clear();
OutTitleGrid->Cols[0]->Clear();
for (short i = 0; i < __size; ++i) { InpTitleGrid->Cells[i][0] = "Q" + IntToStr(i); OutTitleGrid->Cells[0][i] = "O" + IntToStr(i);
}
RegMatrGrid->ScrollBars = System::Uitypes::TScrollStyle::ssNone;
InpQueGrid->ScrollBars = System::Uitypes::TScrollStyle::ssNone; OutputGrid->ScrollBars = System::Uitypes::TScrollStyle::ssNone;
if (__size > 5) {
// clearing and reallocating all simulation-related stuff std::vector time_in_matrix_row;
std::deque packet_issue_ticks;
std::vector packet_reg_matr_ticks(__size, 0);
__packets_in_queue.clear();
__routing_dir.clear();
__packets_processed_row.clear();
__max_i.clear();
__selected_packet_i.clear();
__lock_dir.clear();
__max_time_in_matrix.clear();
__time_in_matrix.clear();
__packet_issue_ticks.clear();
__packet_reg_matr_ticks.clear();
time_in_matrix_row.clear();
for (short i = 0; i < __size; ++i ) {
__packets_in_queue.push_back(0);
__routing_dir.push_back(0);
__packets_processed_row.push_back(0);
__max_i.push_back(0);
__selected_packet_i.push_back(0);
__lock_dir.push_back(false);
__max_time_in_matrix.push_back(0); time_in_matrix_row.push_back(0);
}
for (short i = 0; i < __size; ++i ) {
__time_in_matrix.push_back(time_in_matrix_row);
__packet_issue_ticks.push_back(packet_issue_ticks);
__packet_reg_matr_ticks.push_back(packet_reg_matr_ticks);
}
}
__round_robin_selector = 0;
// scaling the main window and rearranging the controls
if (__RearrangeControls()) {
// enabling the scrollbars
RegMatrGrid->ScrollBars = System::Uitypes::TScrollStyle::ssBoth;
InpQueGrid->ScrollBars = System::Uitypes::TScrollStyle::ssHorizontal; OutputGrid->ScrollBars = System::Uitypes::TScrollStyle::ssVertical;
}
RegMatrGrid->TopRow = 0;
RegMatrGrid->LeftCol = 0;
InpQueGrid->TopRow = 0;
InpQueGrid->LeftCol = 0;
InpTitleGrid->TopRow = 0;
InpTitleGrid->LeftCol = 0;
OutputGrid->TopRow = 0;
OutputGrid->LeftCol = 0;
OutTitleGrid->TopRow = 0;
OutTitleGrid->LeftCol = 0;
InpQueGrid->ColCount = size;
InpTitleGrid->ColCount =_______________ size;
OutputGrid->RowCount =_______________ size;
OutTitleGrid->RowCount = size;
RegMatrGrid->RowCount = size;
RegMatrGrid->ColCount = size;
ResetButtonClick(Sender);
}
}
//------------------------------------------------------------------------
bool TMainWindow::_ RearrangeControls() {
// checking out whether the main window fits in the screen
bool need_scrollbars = false;
short max_allowed_size =____ size;
if (int ScreenHeight; (ScreenHeight = GetSystemMetrics(SM_CYSCREEN)) != 0) {
int required_height;
do {
required_height =
max_allowed_size * (RegMatrGrid->DefaultRowHeight + RegMatrGrid->GridLineWidth) + RegMatrGrid->Top + 31 + InpQueGrid->Height + 3*InpQueGrid->DefaultRowHeight;
--max_allowed_size;
}
while (required_height > ScreenHeight);
if (++max_allowed_size < __size) need_scrollbars = true;
}
// expanging the grids
RegMatrGrid->Width = max_allowed_size * (RegMatrGrid->DefaultColWidth + RegMatrGrid->GridLineWidth);
RegMatrGrid->Height = max_allowed_size * (RegMatrGrid->DefaultColWidth + RegMatrGrid->GridLineWidth); OutputGrid->Height = RegMatrGrid->Height;
InpQueGrid->Width = RegMatrGrid->Width;
OutTitleGrid->Height = RegMatrGrid->Height;
InpTitleGrid->Width = RegMatrGrid->Width;
// moving the output grid and its labels to the right
OutputGrid->Left = RegMatrGrid->Left + RegMatrGrid->Width + 31;
OutTitleGrid->Left = OutputGrid->Left + OutputGrid->Width - 2;
// moving the input queue grid and its labels down
InpQueGrid->Top = RegMatrGrid->Top + RegMatrGrid->Height + 31;
InpTitleGrid->Top = InpQueGrid->Top + InpQueGrid->Height - 2;
// moving the size button
SizeButton->Left = OutputGrid->Left;
SizeButton->Top = InpQueGrid->Top;
// moving the time and phase stat labels TimeTitleLabel->Left = OutputGrid->Left - 16;
PhaseTitleLabel->Left = OutputGrid->Left - 16;
TimeTitleLabel->Top = InpTitleGrid->Top - 2;
PhaseTitleLabel->Top = TimeTitleLabel->Top + 22;
TimeLabel->Left = TimeTitleLabel->Left + 55;
TimeLabel->Top = TimeTitleLabel->Top;
PhaseLabel->Left = PhaseTitleLabel->Left + 55;
PhaseLabel->Top = PhaseTitleLabel->Top;
// expanding and moving the panels and the status bar
SimulPanel->Width = OutTitleGrid->Left + OutTitleGrid->Width + 24;
SimulPanel->Height = InpTitleGrid->Top + 2*InpTitleGrid->Height;
CtrlPanel->Left = SimulPanel->Width + 6;
CtrlPanel->Height = SimulPanel->Height;
StatusBar->Top = SimulPanel->Height + 2;
StatGroupBox->Height = CtrlPanel->Height - StatGroupBox->Top - 15;
StatMemo->Height = StatGroupBox->Height - 50;
// expanding the main window
MainWindow->Width = CtrlPanel->Left + CtrlPanel->Width + 7;
MainWindow->Height = CtrlPanel->Height + StatusBar->Height + 30; MainWindow->Position = poDesktopCenter;
return need_scrollbars;
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::RegMatrGridTopLeftChanged(TObject *Sender)
{
InpTitleGrid->LeftCol = RegMatrGrid->LeftCol;
InpQueGrid->LeftCol = RegMatrGrid->LeftCol;
OutTitleGrid->TopRow = RegMatrGrid->TopRow; OutputGrid->TopRow = RegMatrGrid->TopRow;
}
//------------------------------------------------------------------------
void__ fastcall TMainWindow::InpQueGridTopLeftChanged(TObject *Sender)
{
InpTitleGrid->LeftCol = InpQueGrid->LeftCol;
RegMatrGrid->LeftCol = InpQueGrid->LeftCol;
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::OutputGridTopLeftChanged(TObject *Sender)
{
OutTitleGrid->TopRow = OutputGrid->TopRow; RegMatrGrid->TopRow = OutputGrid->TopRow;
}
//------------------------------------------------------------------------
void __fastcall TMainWindow::ThresholdEditChange(TObject *Sender)
{
if (ThresholdEdit->Text == "")____ time_threshold = -1;
}
//------------------------------------------------------------------------
int TMainWindow::__PacketsInRegMatrixRow(short row) const {
int count = 0;
for (short k = 0; k Cells[k][row] != "") ++count;
return count;
}
int TMainWindow::__PacketsInRegMatrixCol(short col) const {
int count = 0;
for (short k = 0; k < __size; ++k )
if (RegMatrGrid->Cells[col][k] != "") ++count;
return count;
}
int TMainWindow::__PacketsInRegMatrix() const {
int count = 0;
for (short k = 0; k < __size; ++k ) {
for (short i = 0; i < __size; ++i )
if (RegMatrGrid->Cells[k][i] != "") ++count;
}
return count;
}
//------------------------------------------------------------------------
bool TMainWindow::__RegMatrixEmpty() const {
return __PacketsInRegMatrix() == 0;
}
//------------------------------------------------------------------------
// файл SzWnd.h - определение класса окна задания числа входов/выходов КУ
//------------------------------------------------------------------------
#ifndef szwndH
#define szwndH
//------------------------------------------------------------------------
#include
#include
#include
#include
#include
//------------------------------------------------------------------------
class TSizeWindow : public TForm
{
__published: // IDE-managed Components
TSpinEdit *SizeSpinEdit;
TButton *SetSizeButton;
void __fastcall SetSizeButtonClick(TObject *Sender);
void __fastcall FormDeactivate(TObject *Sender);
void __fastcall FormActivate(TObject *Sender);
private: // User declarations
short __new_size;
bool __new_size_set;
public: // User declarations
__fastcall TSizeWindow(TComponent* Owner);
bool NewSizeSet() const { return __new_size_set; }
short GetNewSize() const { return __new_size; }
};
//------------------------------------------------------------------------
extern PACKAGE TSizeWindow *SizeWindow;
//------------------------------------------------------------------------
#endif
// файл SzWnd.cpp - реализация класса окна задания числа входов/выходов КУ
//------------------------------------------------------------------------
#include
#pragma hdrstop
#include "szwnd.h"
#include "mainwnd.h"
//------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TSizeWindow *SizeWindow;
//------------------------------------------------------------------------
_ fastcall TSizeWindow::TSizeWindow(TComponent* Owner)
: TForm(Owner)
{
}
//------------------------------------------------------------------------
void__ fastcall TSizeWindow::SetSizeButtonClick(TObject *Sender)
{
SizeWindow->Close();
}
//------------------------------------------------------------------------
void__ fastcall TSizeWindow::FormDeactivate(TObject *Sender)
{
_____ new_size = SizeSpinEdit->Value;
__new_size_set = true;
}
//------------------------------------------------------------------------
void__ fastcall TSizeWindow::FormActivate(TObject *Sender)
{
__new_size_set = false;
SizeSpinEdit->Value = MainWindow->GetCurSize();
}
//------------------------------------------------------------------------
Еще по теме Приложение 4 Листинг программы PPP Switch Simulator, используемой для визуализации процесса моделирования КУ:
- Приложение 2 Листинг программы вычисления значения Qiпо формуле (2.22)
- Приложение 1 Листинг программы вычисления значения Q1nпо формуле (2.9)
- Приложение 3 Листинг функции управления контроллеров MC_j, используемых в Q-схеме на рис. 3.1
- Исследование процесса смешивания шихты для низколегированных порошковых сталей
- Приложение Б - Акт внедрения в учебный процесс
- Особенности программной реализации имитационного моделирования коммутационного устройства
- Характеристики используемых порошков
- Оборудование для электроэрозионного измельчения
- Значение срочного рынка для экономики страны
- Значение рынка производных инструментов для экономики страны и история его развития
- Исследование процесса спекания низколегированных порошковых сталей
- Исследование процесса прессования шихты низколегированных порошковых сталей