Skip to content

Commit

Permalink
Use GA.
Browse files Browse the repository at this point in the history
  • Loading branch information
olegshtch committed May 23, 2011
1 parent f4c3e29 commit 316cdf7
Show file tree
Hide file tree
Showing 21 changed files with 615 additions and 416 deletions.
Binary file modified 1.tbl
Binary file not shown.
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ SUBDIRS = 3rd_party \
bin_PROGRAMS = table
table_SOURCES = 3rd_party/BasicExcel.cpp \
3rd_party/ExcelFormat.cpp \
ga/fitness.cpp \
ga/ga.cpp \
ga/graph.cpp \
ga/individual.cpp \
Expand Down
10 changes: 7 additions & 3 deletions src/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ bool DataBase::SetLessonIntoTimetable(long int id_lesson, ORM::ForeignKey id_aud
scheme.add(id);
Glib::RefPtr<ORM::Data> fake_data = ORM::Data::create(scheme);

std::cout << "DataBase::SetLessonIntoTimetable. l=" << id_lesson << " a=" << id_aud << " d=" << day_id << " h=" << hour_id << std::endl;
//LogBuf::Enable(true);
std::cout << "DataBase::SetLessonIntoTimetable" << std::endl;
//checks for free auditorium
ORM::Subquery subquery_free_aud;
subquery_free_aud.Select(fake_data
Expand Down Expand Up @@ -595,6 +595,7 @@ bool DataBase::SetLessonIntoTimetable(long int id_lesson, ORM::ForeignKey id_aud
|| ORM::In(g_ModelAuditoriums.fId, subquery_unapp_aud)));
if(fake_data->children().size() > 0)
{
std::cout << "DataBase::SetLessonIntoTimetable. No free auditorium" << std::endl;
return false;
}

Expand Down Expand Up @@ -629,6 +630,7 @@ bool DataBase::SetLessonIntoTimetable(long int id_lesson, ORM::ForeignKey id_aud
|| ORM::In(g_ModelGroups.fId, subquery_free_grp)));
if(fake_data->children().size() > 0)
{
std::cout << "DataBase::SetLessonIntoTimetable. No free groups" << std::endl;
return false;
}

Expand Down Expand Up @@ -657,6 +659,7 @@ bool DataBase::SetLessonIntoTimetable(long int id_lesson, ORM::ForeignKey id_aud
|| ORM::In(g_ModelTeachers.fId, subquery_free_tch)));
if(fake_data->children().size() > 0)
{
std::cout << "DataBase::SetLessonIntoTimetable. No free teachers" << std::endl;
return false;
}

Expand Down Expand Up @@ -1149,12 +1152,13 @@ long int DataBase::GetTimeTableLessonAuditorium(ORM::ForeignKey id_aud, ORM::For
return -1;
}

void DataBase::ListTLHM(Glib::RefPtr<ORM::Data>& data)
void DataBase::ListTLBHM(Glib::RefPtr<ORM::Data>& data)
{
m_Connection.SelectDistinct(data
, g_ModelLessons.teacher
, g_ModelLessons.fId
, g_ModelLessons.lesson_type
, g_ModelLessons.branch
, g_ModelTeachingPlan.hours
, g_ModelLessonType.multithread)
->From(g_ModelLessons, g_ModelGroupCategory, g_ModelTeachingPlan)
Expand Down Expand Up @@ -1240,7 +1244,7 @@ void DataBase::MoveLessons(long int id_lesson_from, long int id_lesson_to)
m_Connection.DeleteFrom(g_ModelLessons)->Where(ORM::Eq(g_ModelLessons.fId, ORM::PrimaryKey(id_lesson_from)));
}

bool DataBase::InterseptLessons(long int id_lesson1, long int id_lesson2)
bool DataBase::InterseptGroups(long int id_lesson1, long int id_lesson2)
{
ORM::Subquery groups1;
Glib::RefPtr<ORM::Data> fake_data;
Expand Down
4 changes: 2 additions & 2 deletions src/db/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ namespace DB
Glib::ustring GetTimeTableLessonAuditoriumText(ORM::ForeignKey id_aud, ORM::ForeignKey id_hour, ORM::ForeignKey id_day);
long int GetTimeTableLessonAuditorium(ORM::ForeignKey id_aud, ORM::ForeignKey id_hour, ORM::ForeignKey id_day);

void ListTLHM(Glib::RefPtr<ORM::Data>& data);
void ListTLBHM(Glib::RefPtr<ORM::Data>& data);
size_t CountAuditoriums(bool multithread, ORM::ForeignKey id_day, ORM::ForeignKey id_hour);

bool GetLessonHolydays(long int lesson_id, long int day_id, long int hour_id);

void MoveLessons(long int id_lesson_from, long int id_lesson_to);
bool InterseptLessons(long int id_lesson1, long int id_lesson2);
bool InterseptGroups(long int id_lesson1, long int id_lesson2);
Glib::ustring GetStreamByLesson(ORM::ForeignKey id_lesson);
bool IsGroupsInStream(long int id_lesson, long int id_subgroup);
void RemoveSubgroupFromLesson(long int id_lesson, long int id_subgroup);
Expand Down
83 changes: 67 additions & 16 deletions src/export_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ ExportDialog::ExportDialog(GtkDialog *cobject, const Glib::RefPtr<Gtk::Builder>&
m_ExportCategory->pack_start(DB::g_IdTextScheme.fText);
Gtk::TreeIter iter = m_refCategory->append();
iter->set_value(DB::g_IdTextScheme.fId, 1l);
iter->set_value(DB::g_IdTextScheme.fText, Glib::ustring(_("Groups")));
iter->set_value(DB::g_IdTextScheme.fText, Glib::ustring(_("Группы")));
m_ExportCategory->set_active(iter);
iter = m_refCategory->append();
/*iter = m_refCategory->append();
iter->set_value(DB::g_IdTextScheme.fId, 2l);
iter->set_value(DB::g_IdTextScheme.fText, Glib::ustring(_("Teachers")));
iter = m_refCategory->append();
iter->set_value(DB::g_IdTextScheme.fId, 3l);
iter->set_value(DB::g_IdTextScheme.fText, Glib::ustring(_("Auditoriums")));
iter->set_value(DB::g_IdTextScheme.fText, Glib::ustring(_("Auditoriums")));*/
m_ExportCategory->signal_changed().connect(sigc::mem_fun(*this, &ExportDialog::OnExportChanged));

m_ExportedObjects->set_headers_visible(false);
Expand Down Expand Up @@ -90,10 +90,10 @@ void ExportDialog::on_response(int response_id)
if(response_id == Gtk::RESPONSE_YES)
{
#if WIN32
Win32FileDialog dialog(_("Choose file for exporting timetable:"),
Win32FileDialog dialog(_("Выбрать файл для экспорта расписания:"),
Gtk::FILE_CHOOSER_ACTION_SAVE);
dialog.add_filter(_("Microsoft Excel"), "*.xls");
dialog.add_filter(_("All files"), "*");
dialog.add_filter(_("Все файлы"), "*");
dialog.set_def_ext("xls");
#else
Gtk::FileChooserDialog dialog(*this, _("Choose file for exporting timetable:"),
Expand Down Expand Up @@ -128,18 +128,27 @@ void ExportDialog::Export(const Glib::ustring& filename)
{
throw Glib::Error(1, 0, "Cann't get worksheet");
}
worksheet->Rename(WChar(_("Timetable")));
worksheet->Rename(WChar(_("Расписание")));
ExcelFormat::XLSFormatManager format_manager(xls);
ExcelFormat::CellFormat cell_format(format_manager);
cell_format.set_alignment(ExcelFormat::EXCEL_VALIGN_CENTRED | ExcelFormat::EXCEL_HALIGN_CENTRED);
cell_format.set_wrapping(false);
cell_format.set_borderlines(ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, 0
, 0);
YExcel::BasicExcelCell *cell = worksheet->Cell(1, 0);
cell->Set(WChar(_("Day")));
cell->Set(WChar(_("День")));
cell->SetFormat(cell_format);
worksheet->SetColWidth(0, 5000);
cell = worksheet->Cell(1, 1);
cell->Set(WChar(_("Hour")));
cell->Set(WChar(_("Час")));
cell->SetFormat(cell_format);
worksheet->SetColWidth(1, 5000);
cell = worksheet->Cell(0, 2);
cell->Set(WChar(_("Groups")));
cell->Set(WChar(_("Группы")));
cell->SetFormat(cell_format);

//заполнить группами
Expand All @@ -150,7 +159,6 @@ void ExportDialog::Export(const Glib::ustring& filename)
if(iter->get_value(m_ChooseModel.fChoose))
{
groups_list.push_back(std::make_pair(iter->get_value(m_ChooseModel.fId), iter->get_value(m_ChooseModel.fText)));
std::cout << "Add " << iter->get_value(m_ChooseModel.fText) << std::endl;
}
}

Expand All @@ -160,13 +168,40 @@ void ExportDialog::Export(const Glib::ustring& filename)
cell = worksheet->Cell(1, i + 2);
cell->Set(WChar(groups_list[i].second));
cell->SetFormat(cell_format);
cell = worksheet->Cell(0, i + 2);
cell->SetFormat(cell_format);
worksheet->SetColWidth(i + 2, 5000);
}

Glib::RefPtr<ORM::Data> days_list = ORM::Data::create(DB::g_IdTextScheme);
Glib::RefPtr<ORM::Data> hours_list = ORM::Data::create(DB::g_IdTextScheme);
DB::DataBase::Instance().ListEntitiesTextOrderedID(DB::g_ModelDays, DB::g_ModelDays.name, days_list);
DB::DataBase::Instance().ListEntitiesTextOrderedID(DB::g_ModelHours, ORM::Expr<Glib::ustring>(ORM::Expr<Glib::ustring>(DB::g_ModelHours.start) + "-" + DB::g_ModelHours.finish), hours_list);

ExcelFormat::CellFormat cell_top(format_manager);
cell_top.set_borderlines(ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_NO_LINE
, 0
, 0);

ExcelFormat::CellFormat cell_bottom(format_manager);
cell_bottom.set_borderlines(ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_NO_LINE
, ExcelFormat::EXCEL_LS_THICK
, 0
, 0);

ExcelFormat::CellFormat cell_middle(format_manager);
cell_middle.set_borderlines(ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_THICK
, ExcelFormat::EXCEL_LS_NO_LINE
, ExcelFormat::EXCEL_LS_NO_LINE
, 0
, 0);

size_t row = 2;
for(Gtk::TreeIter day = days_list->children().begin(); day != days_list->children().end(); ++ day)
{
Expand All @@ -182,17 +217,33 @@ void ExportDialog::Export(const Glib::ustring& filename)
cell->SetFormat(cell_format);
for(size_t i = 0; i < groups_list.size(); ++ i)
{
cell = worksheet->Cell(row, i + 2);
cell->SetMergedRows(merged_lines);
Glib::ustring timetablestr = DB::DataBase::Instance().GetTimeTableLessonGroupText(groups_list[i].first, hour->get_value(DB::g_IdTextScheme.fId), day->get_value(DB::g_IdTextScheme.fId), m_ShowAuditorium->get_active());
cell->Set(WChar(timetablestr));
Glib::ustring::size_type index_start = 0;
for(size_t j = 0; j < merged_lines; ++ j)
{
cell = worksheet->Cell(row + j, 0);
cell->SetFormat(cell_format);
cell = worksheet->Cell(row + j, 1);
cell->SetFormat(cell_format);

cell = worksheet->Cell(row + j, i + 2);
cell->SetFormat(cell_middle);
Glib::ustring::size_type index_end = timetablestr.find('\n', index_start);
cell->SetWString(WChar(timetablestr.substr(index_start, index_end)));
index_start = index_end + 1;
if(j == 0)
{
cell->SetFormat(cell_top);
}
else if(j == (merged_lines - 1))
{
cell->SetFormat(cell_bottom);
}
}
}
}
}

xls.SaveAs(WChar(filename));
#ifdef WIN32
ShellExecuteW(0, NULL, WChar(filename), NULL, NULL, SW_NORMAL);
#endif
}

3 changes: 1 addition & 2 deletions src/ga/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
noinst_HEADERS = fitness.h \
ga.h \
noinst_HEADERS = ga.h \
graph.h \
individual.h

2 changes: 0 additions & 2 deletions src/ga/fitness.cpp

This file was deleted.

46 changes: 0 additions & 46 deletions src/ga/fitness.h

This file was deleted.

Loading

0 comments on commit 316cdf7

Please sign in to comment.