Skip to content
Snippets Groups Projects
Commit 24211173 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Notizen 20.4.2023: Stundenplan-Algorithmus; Beispiele 27.4.2023

parent cc27bc59
Branches
No related tags found
No related merge requests found
Showing
with 656 additions and 0 deletions
Stundenplan-Algorithmus, 20.04.2023, 17:27:42
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Zum Algorithmus von FET: https://lalescu.ro/liviu/fet/doc/en/generation-algorithm-description.html
gegeben: Input
- Liste der Lehrveranstaltungen
- Liste der Studierendengruppen mit zeitlichen Einschränkungen
- Liste der Lehrenden mit zeitlichen Einschränkungen
für jede Lehrveranstaltung:
Schritt 1: Nächstbesten freien Platz im Stundenplan wählen
Vorbedingungen: einige Lehrveranstaltungen wurden bereits plaziert
Dafür benötigt:
- Funktion, die auf Konflikte prüft: Bitmasken verwenden?
- Funktion, die den nächsten freien Slot findet
Schritt 2: Falls es keinen freien Platz gibt:
- irgendwas anderes wegschieben
- Was??? Wohin???
--> Neue Idee
Falls es keinen freien Platz gibt:
Reihenfolge der "freifliegenden" Lehrveranstaltungen ändern
von vorne beginnen
Stundenplan als Bitmaske:
4 * 11 + 1 = 45 Viertelstunden pro Tag an 5 Tagen pro Woche
= (4 * 11 + 1) * 5 = 225 Bit
Bitmasken für Module berechnen.
Mit dem Modul beginnen, das die wenigsten Möglichkeiten hat.
#include <iostream>
using namespace std;
int main ()
{
int a = 42;
int b = 0;
if (b == 0)
{
cout << "Irgendwas ist schiefgelaufen: Ganzzahldivision durch Null" << endl;
}
else
{
int c = a / b;
cout << "c = " << c << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
try
{
int a = 42;
int b = 0;
if (b == 0)
throw "Ganzzahldivision durch Null";
int c = a / b;
cout << "c = " << c << endl;
}
catch (const char *msg)
{
cout << "Irgendwas ist schiefgelaufen: " << msg << endl;
}
return 0;
}
#include <iostream>
#include <sstream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
static const char *buffer;
public:
philosophy_exception (int a) { answer = a; }
virtual const char *what () const noexcept;
};
const char *philosophy_exception::what () const noexcept
{
return buffer;
// ostringstream buffer;
// buffer << "philosophy exception #" << answer;
// return buffer.str ().c_str ();
}
const char *philosophy_exception::buffer = "Marvin";
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 42)
cout << "And what was the question?" << endl;
else
throw philosophy_exception (answer);
}
catch (exception &e)
{
cout << "caught exception: " << e.what () << endl;
}
return 0;
}
#include <iostream>
#include <sstream>
#include <string.h>
using namespace std;
class philosophy_exception: public exception
{
int answer;
static char buffer[42];
public:
philosophy_exception (int a) { answer = a; }
virtual const char *what () const noexcept;
};
const char *philosophy_exception::what () const noexcept
{
ostringstream tmp_buffer;
tmp_buffer << "philosophy exception #" << answer;
strcpy (buffer, tmp_buffer.str ().c_str ());
return buffer;
}
char philosophy_exception::buffer[42] = "Marvin";
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 42)
cout << "And what was the question?" << endl;
else
throw philosophy_exception (answer);
}
catch (exception &e)
{
cout << "caught exception: " << e.what () << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int a = 42;
int b = 0;
if (b == 0)
{
cout << "Irgendwas ist schiefgelaufen: " << "Ganzzahldivision durch Null" << endl;
return 1;
}
int c = a / b;
cout << "c = " << c << endl;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
try
{
int a = 42;
int b = 0;
if (b == 0)
throw "Ganzzahldivision durch Null";
int c = a / b;
cout << "c = " << c << endl;
}
catch (int msg)
{
cout << "Irgendwas ist schiefgelaufen: " << msg << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
try
{
int a = 42;
int b = 0;
int c = a / b;
cout << "c = " << c << endl;
}
catch (int msg)
{
cout << "Irgendwas ist schiefgelaufen: " << msg << endl;
}
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer != 42)
{
try
{
if (answer == 10)
throw answer;
else if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
throw;
}
throw "bullshit";
}
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
else
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer != 42)
{
try
{
if (answer == 10)
throw answer;
if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
throw;
}
throw "bullshit";
}
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer != 42)
{
try
{
if (answer == 10)
throw answer;
if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
throw;
}
throw "bullshit";
}
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
catch (int e)
{
cout << "caught integer exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer == 42)
return;
try
{
if (answer == 10)
throw answer;
if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
throw;
}
throw "bullshit";
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
catch (int e)
{
cout << "caught integer exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
#include <iostream>
using namespace std;
void check_answer (int answer)
{
if (answer != 42)
{
try
{
if (answer == 10)
throw answer;
else if (answer == 137)
throw "alpha";
}
catch (int e)
{
cout << "Yeah!" << endl;
}
throw "bullshit";
}
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 23)
throw answer;
else
check_answer (answer);
}
catch (const char *e)
{
cout << "caught string exception: " << e << endl;
}
cout << "And what was the question?" << endl;
return 0;
}
#include <iostream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
};
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer != 42)
throw philosophy_exception (answer);
cout << "And what was the question?" << endl;
}
catch (exception &e)
{
cout << "caught exception" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
int get_answer () { return answer; }
};
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer != 42)
throw philosophy_exception (answer);
cout << "And what was the question?" << endl;
}
catch (philosophy_exception &e)
{
cout << "caught philosophy exception: " << e.get_answer () << endl;
}
catch (exception &e)
{
cout << "caught exception" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
int get_answer () { return answer; }
};
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer != 42)
throw philosophy_exception (answer);
cout << "And what was the question?" << endl;
}
catch (exception &e)
{
cout << "caught exception" << endl;
}
catch (philosophy_exception &e)
{
cout << "caught philosophy exception: " << e.get_answer () << endl;
}
return 0;
}
#include <iostream>
#include <sstream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
virtual const char *what ();
};
const char *philosophy_exception::what ()
{
ostringstream buffer;
buffer << "philosophy exception #" << answer;
return buffer.str ().c_str ();
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 42)
cout << "And what was the question?" << endl;
else
throw philosophy_exception (answer);
}
catch (exception &e)
{
cout << "caught exception: " << e.what () << endl;
}
return 0;
}
#include <iostream>
#include <sstream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
virtual const char *what () const noexcept;
};
const char *philosophy_exception::what () const noexcept
{
ostringstream buffer;
buffer << "philosophy exception #" << answer;
return buffer.str ().c_str ();
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 42)
cout << "And what was the question?" << endl;
else
throw philosophy_exception (answer);
}
catch (exception &e)
{
cout << "caught exception: " << e.what () << endl;
}
return 0;
}
#include <iostream>
#include <sstream>
using namespace std;
class philosophy_exception: public exception
{
int answer;
public:
philosophy_exception (int a) { answer = a; }
virtual const char *what () const noexcept;
};
const char *philosophy_exception::what () const noexcept
{
return "Marvin";
// ostringstream buffer;
// buffer << "philosophy exception #" << answer;
// return buffer.str ().c_str ();
}
int main ()
{
int answer;
cout << "What's your answer? ";
cin >> answer;
try
{
if (answer == 42)
cout << "And what was the question?" << endl;
else
throw philosophy_exception (answer);
}
catch (exception &e)
{
cout << "caught exception: " << e.what () << endl;
}
return 0;
}
// exception::what
#include <iostream> // std::cout
#include <exception> // std::exception
struct ooops : std::exception {
virtual const char* what() const noexcept {return "Ooops!\n";}
};
int main () {
try {
throw ooops();
} catch (std::exception& ex) {
std::cout << ex.what();
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment