Commit d01107c2 authored by Maxime's avatar Maxime
Browse files

view finished

parent 4f513a7c
......@@ -11,11 +11,42 @@
using namespace std;
using namespace std::chrono;
void testPerf(void) {
for (int i = 1; i < 21; i++)
{
srand(21465);
graph_t graph;
char filename[20];
sprintf_s(filename, "la%02d.txt", i);
graph = gestionGraph::lecture_fichier(filename);
solution_t sol;
bierwirth_t v = bierwirthManager::generateVector(graph.nb_pieces, graph.nb_machines);
sol.cost = INT16_MAX;
solution::grasp(&sol, graph);
cout << sol.cost << " : " << sol.cost-graph.supposedBestSolution << endl;
}
}
int main() {
srand(21058465);
testPerf();
/*
srand(21465);
graph_t graph;
graph = gestionGraph::lecture_fichier("la06.txt");
graph = gestionGraph::lecture_fichier("la01.txt");
solution_t sol;
bierwirth_t v = bierwirthManager::generateVector(graph.nb_pieces, graph.nb_machines);
......@@ -26,10 +57,11 @@ int main() {
auto after = duration_cast<milliseconds>(system_clock::now().time_since_epoch());
solution::affiche_solution(sol);
cout << "meilleur cout final : " << sol.cost << endl;
cout << sol.cost << endl;
cout << after.count() - before.count() << " ms" << endl;
*/
return 0;
}
\ No newline at end of file
}
......@@ -223,7 +223,7 @@ void solution::grasp(solution_t* sol, graph_t& graphe)
}
while ((nb_it < MAX_IT) && (sol->cost != graphe.supposedBestSolution) && !needToStop)
while ((nb_it < MAX_IT) && (sol->cost > graphe.supposedBestSolution) && !needToStop)
{
nb_neighbours = 0;
count = 0;
......@@ -274,6 +274,7 @@ void solution::grasp(solution_t* sol, graph_t& graphe)
++nb_it;
}
//cout << "Number of iteration : " << nb_it << endl;
}
......
......@@ -2,7 +2,7 @@
#include <stdlib.h>
int main() {
srand(21058465);
srand(21465);
MainForm form;
form.ShowDialog();
......
......@@ -11,19 +11,20 @@
graph_t global_graph;
solution_t global_sol;
bierwirth_t global_v;
bool fileLoaded;
bool stopRequested;
char szFile[1024];
void MainForm::InitializeComponent(void)
{
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea2 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Legend^ legend2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
System::Windows::Forms::DataVisualization::Charting::Series^ series2 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
this->buttonStart = (gcnew System::Windows::Forms::Button());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBoxIteration = (gcnew System::Windows::Forms::TextBox());
this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
this->buttonStop = (gcnew System::Windows::Forms::Button());
this->buttonFile = (gcnew System::Windows::Forms::Button());
this->textBoxFile = (gcnew System::Windows::Forms::TextBox());
......@@ -36,7 +37,12 @@ void MainForm::InitializeComponent(void)
this->textBoxSupposedBest = (gcnew System::Windows::Forms::TextBox());
this->textBoxCurrentBest = (gcnew System::Windows::Forms::TextBox());
this->label6 = (gcnew System::Windows::Forms::Label());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->BeginInit();
this->chart = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
this->listView = (gcnew System::Windows::Forms::ListView());
this->ListViewFile = (gcnew System::Windows::Forms::ColumnHeader());
this->ListViewIteration = (gcnew System::Windows::Forms::ColumnHeader());
this->ListViewCost = (gcnew System::Windows::Forms::ColumnHeader());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart))->BeginInit();
this->SuspendLayout();
//
// buttonStart
......@@ -71,24 +77,6 @@ void MainForm::InitializeComponent(void)
this->textBoxIteration->Size = System::Drawing::Size(93, 20);
this->textBoxIteration->TabIndex = 2;
//
// chart1
//
chartArea2->Name = L"ChartArea1";
this->chart1->ChartAreas->Add(chartArea2);
legend2->Name = L"Legend1";
this->chart1->Legends->Add(legend2);
this->chart1->Location = System::Drawing::Point(363, 9);
this->chart1->Name = L"chart1";
this->chart1->Palette = System::Windows::Forms::DataVisualization::Charting::ChartColorPalette::Excel;
series2->ChartArea = L"ChartArea1";
series2->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Line;
series2->Legend = L"Legend1";
series2->Name = L"Series2";
this->chart1->Series->Add(series2);
this->chart1->Size = System::Drawing::Size(274, 225);
this->chart1->TabIndex = 3;
this->chart1->Text = L"chart1";
//
// buttonStop
//
this->buttonStop->Location = System::Drawing::Point(12, 41);
......@@ -97,6 +85,7 @@ void MainForm::InitializeComponent(void)
this->buttonStop->TabIndex = 4;
this->buttonStop->Text = L"Stop";
this->buttonStop->UseVisualStyleBackColor = true;
this->buttonStop->Click += gcnew System::EventHandler(this, &MainForm::buttonStop_Click);
//
// buttonFile
//
......@@ -193,9 +182,54 @@ void MainForm::InitializeComponent(void)
this->label6->TabIndex = 14;
this->label6->Text = L"Current best solution :";
//
// chart
//
chartArea1->Name = L"ChartArea1";
this->chart->ChartAreas->Add(chartArea1);
this->chart->Location = System::Drawing::Point(373, 9);
this->chart->Name = L"chart";
series1->ChartArea = L"ChartArea1";
series1->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Line;
series1->IsVisibleInLegend = false;
series1->Name = L"Series1";
this->chart->Series->Add(series1);
this->chart->Size = System::Drawing::Size(432, 300);
this->chart->TabIndex = 16;
//
// listView
//
this->listView->Columns->AddRange(gcnew cli::array< System::Windows::Forms::ColumnHeader^ >(3) {
this->ListViewFile, this->ListViewIteration,
this->ListViewCost
});
this->listView->HideSelection = false;
this->listView->Location = System::Drawing::Point(842, 9);
this->listView->Name = L"listView";
this->listView->Size = System::Drawing::Size(304, 300);
this->listView->TabIndex = 17;
this->listView->UseCompatibleStateImageBehavior = false;
this->listView->View = System::Windows::Forms::View::Details;
//
// ListViewFile
//
this->ListViewFile->Text = L"File";
this->ListViewFile->Width = 100;
//
// ListViewIteration
//
this->ListViewIteration->Text = L"Iteration";
this->ListViewIteration->Width = 100;
//
// ListViewCost
//
this->ListViewCost->Text = L"Cost";
this->ListViewCost->Width = 100;
//
// MainForm
//
this->ClientSize = System::Drawing::Size(649, 411);
this->ClientSize = System::Drawing::Size(1175, 353);
this->Controls->Add(this->listView);
this->Controls->Add(this->chart);
this->Controls->Add(this->textBoxCurrentBest);
this->Controls->Add(this->label6);
this->Controls->Add(this->textBoxSupposedBest);
......@@ -208,12 +242,11 @@ void MainForm::InitializeComponent(void)
this->Controls->Add(this->label2);
this->Controls->Add(this->buttonFile);
this->Controls->Add(this->buttonStop);
this->Controls->Add(this->chart1);
this->Controls->Add(this->textBoxIteration);
this->Controls->Add(this->label1);
this->Controls->Add(this->buttonStart);
this->Name = L"MainForm";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->chart))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
......@@ -222,8 +255,6 @@ void MainForm::InitializeComponent(void)
System::Void MainForm::buttonFile_Click(System::Object^ sender, System::EventArgs^ e)
{
OPENFILENAME ofn;
char szFile[1024];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
......@@ -236,16 +267,16 @@ System::Void MainForm::buttonFile_Click(System::Object^ sender, System::EventArg
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
GetOpenFileName(&ofn);
textBoxFile->Text = charToString(string(szFile).substr(string(szFile).find_last_of("/\\") + 1));
global_sol.cost = INT16_MAX;
global_graph = gestionGraph::lecture_fichier(szFile);
global_v = bierwirthManager::generateVector(global_graph.nb_pieces, global_graph.nb_machines);
fileLoaded = true;
stopRequested = false;
textBoxNbMachine->Text = charToString(to_string(global_graph.nb_machines));
textBoxNbPart->Text = charToString(to_string(global_graph.nb_pieces));
textBoxSupposedBest->Text = charToString(to_string(global_graph.supposedBestSolution));
......@@ -271,8 +302,21 @@ char* MainForm::stringToChar(String^ string)
System::Void MainForm::buttonStart_Click(System::Object^ sender, System::EventArgs^ e)
{
//solution::grasp(&global_sol, global_graph);
//textBoxIteration->Text = charToString(to_string(global_sol.cost));
if (!fileLoaded) {
textBoxNbMachine->Text = charToString("Error");
textBoxNbPart->Text = charToString("Error");
textBoxSupposedBest->Text = charToString("Error");
return;
}
stopRequested = false;
global_v = bierwirthManager::generateVector(global_graph.nb_pieces, global_graph.nb_machines);
global_sol = {};
global_sol.cost = INT16_MAX;
textBoxIteration->Text = charToString(to_string(0));
textBoxCurrentBest->Text = charToString(to_string(0));
chart->Series["Series1"]->Points->Clear();
Application::DoEvents();
solution_t new_solution;
solution_t best_neighbour;
......@@ -283,21 +327,10 @@ System::Void MainForm::buttonStart_Click(System::Object^ sender, System::EventAr
int size = global_graph.nb_machines * global_graph.nb_pieces;
bool needToStop = false;
int needToStopCount;
int hash[HASH_SIZE];
for (int i = 0; i < HASH_SIZE; i++)
{
hash[i] = 0;
}
int hash[HASH_SIZE] = {};
while ((nb_it < MAX_IT) && (global_sol.cost != global_graph.supposedBestSolution) && !needToStop)
while ((nb_it < MAX_IT) && (global_sol.cost > global_graph.supposedBestSolution) && !needToStop && !stopRequested)
{
textBoxIteration->Text = charToString(to_string(nb_it));
textBoxCurrentBest->Text = charToString(to_string(global_sol.cost));
Application::DoEvents();
nb_neighbours = 0;
count = 0;
needToStop = false;
......@@ -345,10 +378,25 @@ System::Void MainForm::buttonStart_Click(System::Object^ sender, System::EventAr
}
++nb_it;
textBoxIteration->Text = charToString(to_string(nb_it));
textBoxCurrentBest->Text = charToString(to_string(global_sol.cost));
chart->Series["Series1"]->Points->AddXY(nb_it,global_sol.cost);
Application::DoEvents();
}
auto item = gcnew ListViewItem(textBoxFile->Text);
item->SubItems->Add(charToString(to_string(nb_it)));
item->SubItems->Add(charToString(to_string(global_sol.cost)));
listView->Items->Add(item);
}
System::Void MainForm::buttonStop_Click(System::Object^ sender, System::EventArgs^ e)
{
stopRequested = true;
global_graph = gestionGraph::lecture_fichier(szFile);
}
......@@ -53,7 +53,8 @@ private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBoxIteration;
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
private: System::Windows::Forms::Button^ buttonStop;
private: System::Windows::Forms::Button^ buttonFile;
private: System::Windows::Forms::TextBox^ textBoxFile;
......@@ -70,6 +71,16 @@ private: System::Windows::Forms::TextBox^ textBoxSupposedBest;
private: System::Windows::Forms::TextBox^ textBoxCurrentBest;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart;
private: System::Windows::Forms::ListView^ listView;
private: System::Windows::Forms::ColumnHeader^ ListViewFile;
private: System::Windows::Forms::ColumnHeader^ ListViewIteration;
private: System::Windows::Forms::ColumnHeader^ ListViewCost;
protected:
private:
......@@ -101,4 +112,5 @@ private: char* stringToChar(String^ string);
private: System::Void buttonStart_Click(System::Object^ sender, System::EventArgs^ e);
private: System::Void buttonStop_Click(System::Object^ sender, System::EventArgs^ e);
};
......@@ -78,6 +78,7 @@
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Optimization>MaxSpeed</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies />
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment