Commit 8168a098 authored by Maxime's avatar Maxime
Browse files

wip grasp graphic

parent b99e6bbb
......@@ -8,22 +8,21 @@
graph_t graph;
solution_t sol;
bierwirth_t v;
graph_t global_graph;
solution_t global_sol;
bierwirth_t global_v;
void MainForm::InitializeComponent(void)
{
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea1 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Legend^ legend1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
System::Windows::Forms::DataVisualization::Charting::Series^ series1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
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());
this->buttonStart = (gcnew System::Windows::Forms::Button());
this->openFileDialog1 = (gcnew System::Windows::Forms::OpenFileDialog());
this->label1 = (gcnew System::Windows::Forms::Label());
this->textBoxEvaluation = (gcnew System::Windows::Forms::TextBox());
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());
......@@ -35,6 +34,8 @@ void MainForm::InitializeComponent(void)
this->textBoxNbMachine = (gcnew System::Windows::Forms::TextBox());
this->label5 = (gcnew System::Windows::Forms::Label());
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->SuspendLayout();
//
......@@ -46,6 +47,7 @@ void MainForm::InitializeComponent(void)
this->buttonStart->TabIndex = 0;
this->buttonStart->Text = L"Start";
this->buttonStart->UseVisualStyleBackColor = true;
this->buttonStart->Click += gcnew System::EventHandler(this, &MainForm::buttonStart_Click);
//
// openFileDialog1
//
......@@ -57,32 +59,32 @@ void MainForm::InitializeComponent(void)
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(148, 12);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(119, 13);
this->label1->Size = System::Drawing::Size(107, 13);
this->label1->TabIndex = 1;
this->label1->Text = L"Number of evalutaions :";
this->label1->Text = L"Number of iterations :";
//
// textBoxEvaluation
// textBoxIteration
//
this->textBoxEvaluation->Location = System::Drawing::Point(264, 9);
this->textBoxEvaluation->Name = L"textBoxEvaluation";
this->textBoxEvaluation->Size = System::Drawing::Size(56, 20);
this->textBoxEvaluation->TabIndex = 2;
this->textBoxEvaluation->Text = L"100";
this->textBoxIteration->Location = System::Drawing::Point(264, 9);
this->textBoxIteration->Name = L"textBoxIteration";
this->textBoxIteration->ReadOnly = true;
this->textBoxIteration->Size = System::Drawing::Size(93, 20);
this->textBoxIteration->TabIndex = 2;
//
// chart1
//
chartArea1->Name = L"ChartArea1";
this->chart1->ChartAreas->Add(chartArea1);
legend1->Name = L"Legend1";
this->chart1->Legends->Add(legend1);
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;
series1->ChartArea = L"ChartArea1";
series1->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Line;
series1->Legend = L"Legend1";
series1->Name = L"Series2";
this->chart1->Series->Add(series1);
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";
......@@ -174,9 +176,28 @@ void MainForm::InitializeComponent(void)
this->textBoxSupposedBest->Size = System::Drawing::Size(56, 20);
this->textBoxSupposedBest->TabIndex = 13;
//
// textBoxCurrentBest
//
this->textBoxCurrentBest->Location = System::Drawing::Point(264, 38);
this->textBoxCurrentBest->Name = L"textBoxCurrentBest";
this->textBoxCurrentBest->ReadOnly = true;
this->textBoxCurrentBest->Size = System::Drawing::Size(93, 20);
this->textBoxCurrentBest->TabIndex = 15;
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(148, 41);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(109, 13);
this->label6->TabIndex = 14;
this->label6->Text = L"Current best solution :";
//
// MainForm
//
this->ClientSize = System::Drawing::Size(649, 411);
this->Controls->Add(this->textBoxCurrentBest);
this->Controls->Add(this->label6);
this->Controls->Add(this->textBoxSupposedBest);
this->Controls->Add(this->label5);
this->Controls->Add(this->textBoxNbMachine);
......@@ -188,7 +209,7 @@ void MainForm::InitializeComponent(void)
this->Controls->Add(this->buttonFile);
this->Controls->Add(this->buttonStop);
this->Controls->Add(this->chart1);
this->Controls->Add(this->textBoxEvaluation);
this->Controls->Add(this->textBoxIteration);
this->Controls->Add(this->label1);
this->Controls->Add(this->buttonStart);
this->Name = L"MainForm";
......@@ -201,13 +222,7 @@ void MainForm::InitializeComponent(void)
System::Void MainForm::buttonFile_Click(System::Object^ sender, System::EventArgs^ e)
{
OPENFILENAME ofn;
char szFile[1024];
char szFilter[] = "All\0*.*\0Text\0*.TXT\0";
char nbMach[10];
char nbPiece[10];
char supposedBest[10];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
......@@ -215,7 +230,7 @@ System::Void MainForm::buttonFile_Click(System::Object^ sender, System::EventArg
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = szFilter;
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
......@@ -223,19 +238,17 @@ System::Void MainForm::buttonFile_Click(System::Object^ sender, System::EventArg
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
GetOpenFileName(&ofn);
string base_filename = string(szFile).substr(string(szFile).find_last_of("/\\") + 1);
textBoxFile->Text = charToString(base_filename);
textBoxFile->Text = charToString(string(szFile).substr(string(szFile).find_last_of("/\\") + 1));
graph = gestionGraph::lecture_fichier(szFile);
v = bierwirthManager::generateVector(graph.nb_pieces, graph.nb_machines);
global_sol.cost = INT16_MAX;
global_graph = gestionGraph::lecture_fichier(szFile);
global_v = bierwirthManager::generateVector(global_graph.nb_pieces, global_graph.nb_machines);
sprintf(nbMach, "%d", graph.nb_machines);
sprintf(nbPiece, "%d", graph.nb_pieces);
sprintf(supposedBest, "%d", graph.supposedBestSolution);
textBoxNbMachine->Text = charToString(nbMach);
textBoxNbPart->Text = charToString(nbPiece);
textBoxSupposedBest->Text = charToString(supposedBest);
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));
}
String^ MainForm::charToString(char* str)
......@@ -256,3 +269,86 @@ char* MainForm::stringToChar(String^ string)
return pNewCharStr;
}
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));
solution_t new_solution;
solution_t best_neighbour;
bierwirth_t v;
int nb_neighbours = 0;
int nb_it = 0;
int count;
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;
}
while ((nb_it < MAX_IT) && (global_sol.cost != global_graph.supposedBestSolution) && !needToStop)
{
textBoxIteration->Text = charToString(to_string(nb_it));
textBoxCurrentBest->Text = charToString(to_string(global_sol.cost));
Application::DoEvents();
nb_neighbours = 0;
count = 0;
needToStop = false;
needToStopCount = 0;
best_neighbour.cost = INT_FAST32_MAX;
do
{
v = bierwirthManager::generateVector(global_graph.nb_pieces, global_graph.nb_machines);
new_solution = solution::rechercheLocale(v, global_graph, 1000);
new_solution.v = v;
needToStopCount++;
if (needToStopCount == MAX_COUNT_HASH) {
needToStop = true;
}
} while (solution::sameH(new_solution, hash, HASH_SIZE) && !needToStop);
while (nb_neighbours < MAX_NEIGHBOURS && count < MAX_COUNT && nb_neighbours < 1)
{
new_solution = solution::genNeighbour(new_solution.v, size, global_graph.nb_pieces, global_graph.nb_machines);
v = new_solution.v;
new_solution = solution::rechercheLocale(v, global_graph, 1000);
new_solution.v = v;
if (solution::sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent
{
++nb_neighbours;
}
else
{
++count;
}
if (new_solution.cost < best_neighbour.cost)
{
best_neighbour = new_solution;
}
}
if (best_neighbour.cost < global_sol.cost)
{
global_sol = best_neighbour;
}
++nb_it;
}
}
......@@ -50,7 +50,8 @@ protected:
private: System::Windows::Forms::OpenFileDialog^ openFileDialog1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ textBoxEvaluation;
private: System::Windows::Forms::TextBox^ textBoxIteration;
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
private: System::Windows::Forms::Button^ buttonStop;
......@@ -66,6 +67,9 @@ private: System::Windows::Forms::TextBox^ textBoxNbPart;
private: System::Windows::Forms::TextBox^ textBoxNbMachine;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::TextBox^ textBoxSupposedBest;
private: System::Windows::Forms::TextBox^ textBoxCurrentBest;
private: System::Windows::Forms::Label^ label6;
protected:
private:
......@@ -95,4 +99,6 @@ private: String^ charToString(string str);
private: char* stringToChar(String^ string);
private: System::Void buttonStart_Click(System::Object^ sender, System::EventArgs^ e);
};
......@@ -81,6 +81,8 @@
</ClCompile>
<Link>
<AdditionalDependencies />
<StackReserveSize>16000000</StackReserveSize>
<StackCommitSize>16000000</StackCommitSize>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
......
......@@ -248,7 +248,7 @@ void solution::grasp(solution_t* sol, graph_t& graphe)
new_solution = genNeighbour(new_solution.v, size, graphe.nb_pieces, graphe.nb_machines);
v = new_solution.v;
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
if (sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent
......@@ -266,7 +266,7 @@ void solution::grasp(solution_t* sol, graph_t& graphe)
}
}
if (best_neighbour.cost<sol->cost)
if (best_neighbour.cost < sol->cost)
{
*sol = best_neighbour;
}
......@@ -276,3 +276,6 @@ void solution::grasp(solution_t* sol, graph_t& graphe)
}
}
 Entry.cpp
 MainForm.cpp
C:\Users\poula\Documents\Travail\ZZ2\S3\Aide Décision\TP\TP2\oad-tp2\Code\View\utils.h(15,2): warning C4091: 'static ': ignored on left of 'utils' when no variable is declared
bierwirthManager.obj : MSIL module encountered; incremental linking is disabled for MSIL; performing full link
View.vcxproj -> C:\Users\poula\Documents\Travail\ZZ2\S3\Aide Décision\TP\TP2\oad-tp2\Code\x64\Debug\View.exe
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.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
No preview for this file type
No preview for this file type
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