operations_research/OR_HTML_04/vorwort.html

779 lines
72 KiB
HTML
Raw Normal View History

Version 04 als eigenes Repository Erster Commit des Strangs "Optimierte Entscheidungsfindung mit Python" (Version 04). Die Historie der 71 Commits bis zur Trennung bleibt im uebergeordneten Repository OR_mit_Python liegen, das ab jetzt nur noch Version_03 (eingefroren) verwaltet und Version_04/ ignoriert. Bewusst kein "git subtree split": Der Pfad Version_04/ existiert erst seit der Verzeichnistrennung, ein Split braechte daher nur 7 der 41 einschlaegigen Commits - eine Teilhistorie, die vollstaendig aussieht und es nicht ist. Stand: 5 Teile, 23 Kapitel, 5 Anhaenge, 292 Abschnitte, 703 Querverweise, 325 Indexmarken, 73 Beispielprogramme, 32 SVGs, 4 Plotly-Figuren, 25 Notebooks, PDF mit 715 Seiten. Zusaetzlich in diesem Commit: * pyproject.toml mit Abhaengigkeitsgruppen finance, large-scale, api, figures, dev, empfehlungen. Die abgedruckte requirements.txt bleibt unveraendert daneben bestehen. ortools steht in der Grundausstattung, highspy erst in [large-scale] - so kann der HiGHS-Symbolkonflikt bei der schlanken Installation gar nicht erst auftreten. * Dabei zwei Funde: graphviz wird von erzeuge_architektur_diagramme.py importiert, fehlt aber in requirements.txt (jetzt in [figures]); pymoo steht in requirements.txt, wird aber von keinem Programm importiert, sondern nur im Kapitel Metaheuristiken empfohlen (jetzt in [empfehlungen]). * NEUER_TITEL.md nach Kritik_und_Verbesserungsvorschlaege/ verschoben - es ist die Vorlage des Titelblatts, kein Bestandteil des Werks. Die beiden Fundstellen in PROGRESS.md und erzeuge_titelseite.py nachgezogen. * PROGRESS.md nannte noch den Untertitel der ersten Fassung; auf den tatsaechlichen aus erzeuge_titelseite.py korrigiert. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 01:20:09 +02:00
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Vorwort & Lesehilfe · Optimierte Entscheidungsfindung mit Python</title>
<script>
(function () {
try {
var t = localStorage.getItem("or-theme");
if (t) document.documentElement.setAttribute("data-theme", t);
} catch (e) {}
})();
</script>
<link rel="stylesheet" href="assets/highlight.css" />
<link rel="stylesheet" href="katex/katex.min.css" />
<script defer="" src="katex/katex.min.js"></script>
<script>document.addEventListener("DOMContentLoaded", function () {
var mathElements = document.getElementsByClassName("math");
var macros = [];
for (var i = 0; i < mathElements.length; i++) {
var texText = mathElements[i].firstChild;
if (mathElements[i].tagName == "SPAN") {
katex.render(texText.data, mathElements[i], {
displayMode: mathElements[i].classList.contains('display'),
throwOnError: false,
macros: macros,
fleqn: false
});
}}
// Der Browser springt zu einem #anker in der URL schon beim ersten Rendern
// an, BEVOR die KaTeX-Formeln oben im Text ihre finale Hoehe bekommen -
// durch den Reflow landet der Anker danach zu weit unten. Nach dem
// Formel-Rendering hier erneut zum Anker springen, das behebt es.
if (location.hash) {
var ziel = document.getElementById(decodeURIComponent(location.hash.slice(1)));
if (ziel) ziel.scrollIntoView({behavior: "instant", block: "start"});
}
});
</script>
<link rel="stylesheet" href="assets/site.css" />
</head>
<body>
<svg style="display:none" aria-hidden="true"><symbol id="icon-menu" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/>
</symbol>
<symbol id="icon-search" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
<circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.2" y2="16.2"/>
</symbol>
<symbol id="icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">
<circle cx="12" cy="12" r="4.5"/>
<line x1="12" y1="1.5" x2="12" y2="4"/><line x1="12" y1="20" x2="12" y2="22.5"/>
<line x1="1.5" y1="12" x2="4" y2="12"/><line x1="20" y1="12" x2="22.5" y2="12"/>
<line x1="4.5" y1="4.5" x2="6.2" y2="6.2"/><line x1="17.8" y1="17.8" x2="19.5" y2="19.5"/>
<line x1="19.5" y1="4.5" x2="17.8" y2="6.2"/><line x1="6.2" y1="17.8" x2="4.5" y2="19.5"/>
</symbol>
<symbol id="icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M20 14.5A8.5 8.5 0 1 1 9.5 4a6.8 6.8 0 0 0 10.5 10.5z"/>
</symbol>
<symbol id="icon-chevron-left" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="15 4 7 12 15 20"/>
</symbol>
<symbol id="icon-chevron-right" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 4 17 12 9 20"/>
</symbol>
<symbol id="icon-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="4 13 9.5 18.5 20 6"/>
</symbol>
<symbol id="icon-external-link" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M18 13.5V19a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 19V7A1.5 1.5 0 0 1 5 5.5h5.5"/>
<polyline points="14.5 3.5 20.5 3.5 20.5 9.5"/><line x1="11" y1="13" x2="20" y2="4"/>
</symbol>
<symbol id="icon-book" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M4 5.5A2 2 0 0 1 6 4h6v16H6a2 2 0 0 0-2 1.5z"/>
<path d="M20 5.5A2 2 0 0 0 18 4h-6v16h6a2 2 0 0 1 2 1.5z"/>
</symbol>
<symbol id="icon-copy" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
</symbol>
<symbol id="icon-download" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 3v12"/><polyline points="7 10 12 15 17 10"/><path d="M4 19.5h16"/>
</symbol></svg>
<header class="site-header">
<button type="button" class="icon-btn" id="sidebar-toggle" aria-label="Menü öffnen"><svg class="icon" aria-hidden="true"><use href="#icon-menu"></use></svg></button>
<a class="brand" href="index.html"><svg class="icon" aria-hidden="true"><use href="#icon-book"></use></svg> <span>Optimierte Entscheidungsfindung mit Python</span></a>
<div class="site-search">
<input id="suche-eingabe" type="search" placeholder="Suchen …" aria-label="Suche" autocomplete="off" />
<svg class="icon such-icon" aria-hidden="true"><use href="#icon-search"></use></svg>
<div id="suche-ergebnisse" class="suche-ergebnisse" hidden></div>
</div>
<button type="button" class="icon-btn" id="theme-toggle" aria-label="Darstellung umschalten">
<svg class="icon icon-sun" aria-hidden="true"><use href="#icon-sun"></use></svg><svg class="icon icon-moon" aria-hidden="true"><use href="#icon-moon"></use></svg>
</button>
</header>
<div class="site-body">
<div class="sidebar-overlay" id="sidebar-overlay" hidden></div>
<nav class="sidebar" id="sidebar" aria-label="Kapitelnavigation"><div class="sidebar-inhalt"><details class="sidebar-gruppe" open><summary>Einstieg</summary><ul><li data-kapitel="vorwort.html" class="aktiv"><a href="vorwort.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Vorwort & Lesehilfe</span></a></li><li data-kapitel="notation.html"><a href="notation.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Notation & Abkürzungen</span></a></li></ul></details><details class="sidebar-gruppe"><summary>Teil I: Grundlagen des Operations Research</summary><ul><li data-kapitel="einfuehrung.html"><a href="einfuehrung.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 1: Einführung in Operations Research — Vom Ursprung zur mathematischen Entscheidungsfindung</span></a></li><li data-kapitel="fundament.html"><a href="fundament.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 2: Das mathematische Fundament — Vektoren, Matrizen, Konvexität</span></a></li><li data-kapitel="oekosystem.html"><a href="oekosystem.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 3: Das Python-Ökosystem für OR — Solver, Bindings und Modellierungsschichten</span></a></li><li data-kapitel="modellierung.html"><a href="modellierung.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 4: Vom Management-Wunsch zum Modell</span></a></li></ul></details><details class="sidebar-gruppe"><summary>Teil II: Die Kernverfahren der deterministischen Optimierung</summary><ul><li data-kapitel="lp.html"><a href="lp.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 5: Lineare Programmierung — Simplex, Dualität und Schattenpreise</span></a></li><li data-kapitel="milp.html"><a href="milp.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 6: Gemischt-ganzzahlige Optimierung — Diskrete Entscheidungen und Branch-and-Bound</span></a></li><li data-kapitel="cpsat.html"><a href="cpsat.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 7: Constraint Programming mit CP-SAT — Logik, Scheduling und Zuweisung</span></a></li><li data-kapitel="graphen.html"><a href="graphen.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 8: Graphen, Flüsse und Touren — Min-Cost-Flow, Matching und VRP</span></a></li><li data-kapitel="metaheuristiken.html"><a href="metaheuristiken.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 9: Metaheuristiken — wenn der exakte Solver aussteigt</span></a></li><li data-kapitel="dekomposition.html"><a href="dekomposition.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 10: Spaltengenerierung — das Modell umbauen statt die Lösung raten</span></a></li></ul></details><details class="sidebar-gruppe"><summary>Teil III: Nichtlinearität, Unsicherheit und mehrperiodige Dynamik</summary><ul><li data-kapitel="qp-nlp.html"><a href="qp-nlp.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-check"></use></svg></span><span>Kapitel 11: Quadratische und nichtlineare Optimierung — KKT, Lagrange, Konvexität</span></a></li><li data-kapitel="unsicherheit.html"><a href="unsicherheit.html"><span class="fortschritt-haken"><svg class="icon" aria-hidden="true"><use href="#icon-ch
<main class="content">
<nav class="breadcrumb" aria-label="Breadcrumb"><a href="index.html">Start</a> <span>Vorwort & Lesehilfe</span></nav>
<nav class="prev-next"><span class="prev-next-leer"></span><a class="prev-next-knopf prev-next-next" href="notation.html"><span><small>Weiter</small>Notation & Abkürzungen</span><svg class="icon" aria-hidden="true"><use href="#icon-chevron-right"></use></svg></a></nav>
<article>
<figure>
<img src="bilder_04/titelseite.svg" alt="Titelseite — Optimierte Entscheidungsfindung mit Python · Dieter Schlüter" />
<figcaption>Titelseite — Optimierte Entscheidungsfindung mit Python · Dieter Schlüter</figcaption>
</figure>
<hr />
<h1 class="unnumbered" id="optimierte-entscheidungsfindung-mit-python">Optimierte Entscheidungsfindung mit Python</h1>
<h2 class="unnumbered" id="von-der-mathematischen-modellierung-zu-praktischen-intelligenten-lösungen-für-betrieb-technik-und-finanzmärkte">Von der mathematischen Modellierung zu praktischen intelligenten Lösungen für Betrieb, Technik und Finanzmärkte</h2>
<p><strong>Ein praxisorientiertes Kompendium für Entscheider</strong> mit Constraint Programming, Vektor- und Matrixmethoden sowie HiGHS, SciPy, Google OR-Tools und CVXPY.</p>
<p>Von <strong>Personaleinsatz-, Schicht- und Vertretungsplänen, Fahrtrouten, Logistik und Maschinen- und Netzwerkauslastung</strong> über <strong>Energieverteilung und Ressourcenplanung</strong> bis zur <strong>Portfoliooptimierung und besseren Entscheidungen an den Finanzmärkten</strong> — mit Python modellieren, optimieren und belegbar fundierte Entscheidungen treffen.</p>
<p>Autor / Herausgeber: Dieter Schlüter</p>
<p>&lt;dieter(dot)schlueter(atsign)linix(dot)de&gt;</p>
<p>Stand: 8. September 2026</p>
<hr />
<h2 class="unnumbered" id="vorwort">Vorwort</h2>
<p>Dieses Buch hat ein einziges Ziel: <strong>Sie sollen am Ende in der Lage sein, ein reales Entscheidungsproblem aus Ihrem eigenen Umfeld in ein mathematisches Modell zu übersetzen, es in Python zu lösen und das Ergebnis jemandem zu erklären, der kein Mathematiker ist.</strong></p>
<p>Dieses Kompendium versteht sich als <strong>Arbeitsbuch</strong>. Das zeigt sich an drei Stellen:</p>
<p><strong>Erstens: Formeln werden übersetzt.</strong> Zu jeder nicht-trivialen Formel gehört in dieser Ausgabe eine Lesehilfe, die jedes Symbol einzeln benennt, und eine Umschreibung in Alltagssprache. Formeln sind eine Abkürzung für Menschen, die den Inhalt schon kennen — wer ihn erst lernt, braucht den ausgeschriebenen Text daneben. Niemand sollte an der Notation scheitern, wenn er den Gedanken versteht.</p>
<p><strong>Zweitens: Es wird geübt.</strong> Über 130 Aufgaben mit vollständigen Lösungen begleiten die Kapitel. Sie sind gestaffelt: von Verständnisfragen, die man im Kopf beantwortet, über Handrechnungen bis zu Programmieraufgaben, die auf den Kapitelbeispielen aufbauen. Wer Optimierung nur liest, kann anschließend über Optimierung reden. Wer die Aufgaben rechnet, kann optimieren.</p>
<p><strong>Drittens: Der Weg zur eigenen Anwendung ist ausgeschildert.</strong> Die Projektwerkstatt am Ende enthält elf vollständig ausgearbeitete Projektaufträge — vom Schul-Vertretungsplaner über die Tourenoptimierung eines Lieferdienstes bis zum eigenen Portfolio-Rebalancer. Jeder Auftrag nennt Datenquellen, Modellskizze, Abnahmekriterien und Stolperfallen. Sie sind so zugeschnitten, dass sie in 10 bis 25 Stunden zu einem vorzeigbaren Ergebnis führen.</p>
<hr />
<h2 class="unnumbered" id="ziel-der-masterclass">Ziel der Masterclass</h2>
<p>Ein umfassendes, didaktisch von Grund auf aufgebautes Lehrbuch zur mathematischen Entscheidungsoptimierung (<strong>Operations Research, OR</strong>) mit praktischer Umsetzung in <strong>Python</strong>. Dieser Kurs der <strong>mathematischen Optimierung</strong> setzt kein Vorwissen in OR voraus und führt schrittweise von den algebraischen und kombinatorischen Grundlagen über Scheduling- und Constraint-Modelle bis hin zur professionellen Anwendung im quantitativen Aktienhandel, Portfoliomanagement und Risikocontrolling.</p>
<h3 class="unnumbered" id="vorausgesetzte-kenntnisse">Vorausgesetzte Kenntnisse</h3>
<p>Vorausgesetzt werden <strong>sichere Python-Kenntnisse</strong> (Funktionen, Klassen, NumPy, pandas) sowie Mathematik auf Grundstudiumsniveau:</p>
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th>Gebiet</th>
<th>Was Sie können sollten</th>
<th>Wo im Buch gebraucht</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Lineare Algebra</strong></td>
<td>Vektoren, Matrizen, Matrix-Vektor-Produkt, Eigenwerte</td>
<td>ab <a href="fundament.html#kap-fundament">Kapitel 2</a>, zentral in <a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a>, <a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a>, <a href="markowitz.html#kap-markowitz">Kapitel 19</a></td>
</tr>
<tr class="even">
<td><strong>Analysis</strong></td>
<td>Ableitung, Gradient, notwendige Bedingung erster Ordnung</td>
<td><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a></td>
</tr>
<tr class="odd">
<td><strong>Statistik</strong></td>
<td>Erwartungswert, Varianz, Standardabweichung, Quantil</td>
<td><a href="unsicherheit.html#kap-unsicherheit">Kapitel 12</a>, 1114</td>
</tr>
<tr class="even">
<td><strong>Python</strong></td>
<td>Listen, Dictionaries, Schleifen, Funktionen, Klassen, NumPy-Arrays</td>
<td>durchgängig</td>
</tr>
</tbody>
</table>
<blockquote>
<p><strong>Wenn Ihnen Mathematik-Bausteine fehlen:</strong> <a href="fundament.html#kap-fundament">Kapitel 2</a> fasst die benötigte lineare Algebra vollständig zusammen, <a href="qp-nlp.html#sec:qp-nlp-lernziele">Abschnitt 11.2</a> wiederholt Gradienten. Sie können also einsteigen und die Lücken unterwegs schließen. Nur die Statistik ab <a href="bruecke.html#teil-anwendungen">Teil IV</a> setzt wirklich Vorwissen voraus — dort hilft ein Blick in ein Einführungswerk zur Wahrscheinlichkeitsrechnung.</p>
</blockquote>
<h3 class="unnumbered" id="benötigte-ressourcen">Benötigte Ressourcen</h3>
<p>Ein Rechner mit Python 3.10 oder neuer genügt. <strong>Spezial-Hardware (GPU) ist nicht nötig</strong> — sämtliche Beispiele laufen auf einem gewöhnlichen Notebook, die meisten in unter zehn Sekunden. Die <a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a> bis 14 benötigen einen <strong>Internetzugang</strong>, da sie aktuelle Kursdaten über <code>yfinance</code> laden.</p>
<hr />
<h2 class="unnumbered" id="setup-installation">Setup &amp; Installation</h2>
<p>Alle Beispielprogramme sind unter Python 3.10+ lauffähig. Legen Sie zunächst eine virtuelle Umgebung an — so bleiben die Kurspakete von Ihrer Systeminstallation getrennt:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="ex">python3</span> <span class="at">-m</span> venv .venv</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="bu">source</span> .venv/bin/activate <span class="co"># Windows: .venv\Scripts\activate</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="ex">pip</span> install <span class="at">--upgrade</span> pip</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="ex">pip</span> install ortools highspy cvxpy scikit-learn yfinance matplotlib pandas numpy scipy <span class="dt">\</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> openpyxl polars plotly pyomo linopy pymoo pydantic</span></code></pre></div>
<p>Alternativ liegt im Ordner <code>Operations_Research_mit_Python_Version_04_Programme/</code> eine <code>requirements.txt</code>:</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="ex">pip</span> install <span class="at">-r</span> Operations_Research_mit_Python_Version_04_Programme/requirements.txt</span></code></pre></div>
<h3 class="unnumbered" id="installationstest">Installationstest</h3>
<p>Prüfen Sie mit diesem Skript, ob alles bereitsteht, <strong>bevor</strong> Sie mit <a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a> beginnen. Es meldet für jedes Paket Version und Status und löst ein Mini-Optimierungsproblem.</p>
<p>Eine Besonderheit dabei — die Import-Reihenfolge ist bewusst gewählt: <code>highspy</code> und <code>cvxpy</code> werden in der Paketübersicht nur auf Anwesenheit geprüft, und <code>ortools</code> lädt seine native Bibliothek zuerst. Der Grund: <code>ortools</code> und <code>highspy</code> bringen jeweils eine eigene HiGHS-Kopie mit, die sich nicht im selben Python-Prozess verträgt — und <code>cvxpy</code> importiert ein installiertes <code>highspy</code> bei der Solver-Erkennung selbst mit. Lädt deren HiGHS-Kopie zuerst, bricht der Test beim CP-SAT-Funktionstest mit einem kryptischen <code>ImportError: undefined symbol</code> ab; so gewinnt die Kopie von <code>ortools</code>, und CVXPY verzichtet lediglich auf sein HIGHS-Interface (für alle Buchprogramme folgenlos). Details und Abhilfen: <a href="oekosystem.html#sec:oekosystem-ein-system-vier-programmieransaetze">Abschnitt 3.5</a> und <a href="anhang-fehlerdiagnose.html#anhang-fehlerdiagnose">Anhang C</a>.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env python3</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"># Installationstest.py</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a><span class="co">&quot;&quot;&quot;</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="co">Vorspann: Prüft die vollständige Kurs-Installation.</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="co">Ausgabe: eine Zeile pro Paket plus ein gelöstes Mini-Modell je Solver-Familie.</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="co">&quot;&quot;&quot;</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> importlib.metadata</span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> importlib.util</span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> logging</span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> sys</span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a>PAKETE <span class="op">=</span> [</span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;numpy&quot;</span>, <span class="st">&quot;Numerische Basis (Vektoren, Matrizen)&quot;</span>),</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;scipy&quot;</span>, <span class="st">&quot;Wissenschaftliche Algorithmen, linprog/minimize&quot;</span>),</span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;pandas&quot;</span>, <span class="st">&quot;Tabellen und Zeitreihen&quot;</span>),</span>
<span id="cb3-18"><a href="#cb3-18" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;matplotlib&quot;</span>, <span class="st">&quot;Diagramme&quot;</span>),</span>
<span id="cb3-19"><a href="#cb3-19" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;ortools&quot;</span>, <span class="st">&quot;Google OR-Tools: CP-SAT und Routing&quot;</span>),</span>
<span id="cb3-20"><a href="#cb3-20" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;highspy&quot;</span>, <span class="st">&quot;HiGHS-Solver, direkte Steuerung&quot;</span>),</span>
<span id="cb3-21"><a href="#cb3-21" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;cvxpy&quot;</span>, <span class="st">&quot;Konvexe Optimierung (Portfolio, CVaR)&quot;</span>),</span>
<span id="cb3-22"><a href="#cb3-22" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;sklearn&quot;</span>, <span class="st">&quot;Ledoit-Wolf-Shrinkage der Kovarianzmatrix&quot;</span>),</span>
<span id="cb3-23"><a href="#cb3-23" aria-hidden="true" tabindex="-1"></a> (<span class="st">&quot;yfinance&quot;</span>, <span class="st">&quot;Kursdatenbezug (nur die Finanzkapitel)&quot;</span>),</span>
<span id="cb3-24"><a href="#cb3-24" aria-hidden="true" tabindex="-1"></a>]</span>
<span id="cb3-25"><a href="#cb3-25" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-26"><a href="#cb3-26" aria-hidden="true" tabindex="-1"></a><span class="co"># Nur auf Anwesenheit prüfen, NICHT importieren (siehe Kapitel Ökosystem):</span></span>
<span id="cb3-27"><a href="#cb3-27" aria-hidden="true" tabindex="-1"></a><span class="co"># - highspy: seine HiGHS-Bibliothek verträgt sich nicht mit der Kopie von</span></span>
<span id="cb3-28"><a href="#cb3-28" aria-hidden="true" tabindex="-1"></a><span class="co"># ortools im selben Prozess.</span></span>
<span id="cb3-29"><a href="#cb3-29" aria-hidden="true" tabindex="-1"></a><span class="co"># - cvxpy: importiert bei der Solver-Erkennung ein installiertes highspy</span></span>
<span id="cb3-30"><a href="#cb3-30" aria-hidden="true" tabindex="-1"></a><span class="co"># selbst mit und löst so denselben Konflikt aus. Importiert wird cvxpy</span></span>
<span id="cb3-31"><a href="#cb3-31" aria-hidden="true" tabindex="-1"></a><span class="co"># erst im Funktionstest, nachdem ortools bereits geladen ist.</span></span>
<span id="cb3-32"><a href="#cb3-32" aria-hidden="true" tabindex="-1"></a>NUR_PRUEFEN <span class="op">=</span> {<span class="st">&quot;highspy&quot;</span>, <span class="st">&quot;cvxpy&quot;</span>}</span>
<span id="cb3-33"><a href="#cb3-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-34"><a href="#cb3-34" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> paket_version(name: <span class="bu">str</span>) <span class="op">-&gt;</span> <span class="bu">str</span>:</span>
<span id="cb3-35"><a href="#cb3-35" aria-hidden="true" tabindex="-1"></a> <span class="co">&quot;&quot;&quot;Liefert die installierte Version; ImportError, falls das Paket fehlt.&quot;&quot;&quot;</span></span>
<span id="cb3-36"><a href="#cb3-36" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> name <span class="kw">in</span> NUR_PRUEFEN:</span>
<span id="cb3-37"><a href="#cb3-37" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> importlib.util.find_spec(name) <span class="kw">is</span> <span class="va">None</span>:</span>
<span id="cb3-38"><a href="#cb3-38" aria-hidden="true" tabindex="-1"></a> <span class="cf">raise</span> <span class="pp">ImportError</span>(name) <span class="co"># nicht installiert</span></span>
<span id="cb3-39"><a href="#cb3-39" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb3-40"><a href="#cb3-40" aria-hidden="true" tabindex="-1"></a> <span class="co"># Version aus den Metadaten — das Modul wird ja nicht geladen</span></span>
<span id="cb3-41"><a href="#cb3-41" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> importlib.metadata.version(name)</span>
<span id="cb3-42"><a href="#cb3-42" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span> importlib.metadata.PackageNotFoundError:</span>
<span id="cb3-43"><a href="#cb3-43" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="st">&quot;unbekannt&quot;</span> <span class="co"># installiert, aber ohne Metadaten</span></span>
<span id="cb3-44"><a href="#cb3-44" aria-hidden="true" tabindex="-1"></a> modul <span class="op">=</span> importlib.import_module(name)</span>
<span id="cb3-45"><a href="#cb3-45" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="bu">getattr</span>(modul, <span class="st">&quot;__version__&quot;</span>, <span class="st">&quot;unbekannt&quot;</span>)</span>
<span id="cb3-46"><a href="#cb3-46" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-47"><a href="#cb3-47" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> pruefe_pakete() <span class="op">-&gt;</span> <span class="bu">list</span>[<span class="bu">str</span>]:</span>
<span id="cb3-48"><a href="#cb3-48" aria-hidden="true" tabindex="-1"></a> <span class="co">&quot;&quot;&quot;Prüft jedes Paket und meldet Version oder Fehlgrund.&quot;&quot;&quot;</span></span>
<span id="cb3-49"><a href="#cb3-49" aria-hidden="true" tabindex="-1"></a> fehlend <span class="op">=</span> []</span>
<span id="cb3-50"><a href="#cb3-50" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;Python-Version: </span><span class="sc">{</span>sys<span class="sc">.</span>version<span class="sc">.</span>split()[<span class="dv">0</span>]<span class="sc">}</span><span class="ch">\n</span><span class="ss">&quot;</span>)</span>
<span id="cb3-51"><a href="#cb3-51" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;</span><span class="sc">{</span><span class="st">&#39;Paket&#39;</span><span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span><span class="st">&#39;Version&#39;</span><span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span><span class="st">&#39;Zweck&#39;</span><span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-52"><a href="#cb3-52" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;-&quot;</span> <span class="op">*</span> <span class="dv">78</span>)</span>
<span id="cb3-53"><a href="#cb3-53" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> name, zweck <span class="kw">in</span> PAKETE:</span>
<span id="cb3-54"><a href="#cb3-54" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
<span id="cb3-55"><a href="#cb3-55" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;</span><span class="sc">{</span>name<span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span>paket_version(name)<span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span>zweck<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-56"><a href="#cb3-56" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span> <span class="pp">ImportError</span>:</span>
<span id="cb3-57"><a href="#cb3-57" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;</span><span class="sc">{</span>name<span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span><span class="st">&#39;FEHLT&#39;</span><span class="sc">:&lt;12}</span><span class="ss"> </span><span class="sc">{</span>zweck<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-58"><a href="#cb3-58" aria-hidden="true" tabindex="-1"></a> fehlend.append(name)</span>
<span id="cb3-59"><a href="#cb3-59" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> fehlend</span>
<span id="cb3-60"><a href="#cb3-60" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-61"><a href="#cb3-61" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> teste_cp_sat() <span class="op">-&gt;</span> <span class="bu">bool</span>:</span>
<span id="cb3-62"><a href="#cb3-62" aria-hidden="true" tabindex="-1"></a> <span class="co">&quot;&quot;&quot;Löst &#39;maximiere x+y unter x+2y&lt;=10, x&lt;=4&#39; mit CP-SAT. Erwartet: x=4, y=3.&quot;&quot;&quot;</span></span>
<span id="cb3-63"><a href="#cb3-63" aria-hidden="true" tabindex="-1"></a> <span class="im">from</span> ortools.sat.python <span class="im">import</span> cp_model</span>
<span id="cb3-64"><a href="#cb3-64" aria-hidden="true" tabindex="-1"></a> modell <span class="op">=</span> cp_model.CpModel()</span>
<span id="cb3-65"><a href="#cb3-65" aria-hidden="true" tabindex="-1"></a> x <span class="op">=</span> modell.NewIntVar(<span class="dv">0</span>, <span class="dv">4</span>, <span class="st">&quot;x&quot;</span>)</span>
<span id="cb3-66"><a href="#cb3-66" aria-hidden="true" tabindex="-1"></a> y <span class="op">=</span> modell.NewIntVar(<span class="dv">0</span>, <span class="dv">10</span>, <span class="st">&quot;y&quot;</span>)</span>
<span id="cb3-67"><a href="#cb3-67" aria-hidden="true" tabindex="-1"></a> modell.Add(x <span class="op">+</span> <span class="dv">2</span> <span class="op">*</span> y <span class="op">&lt;=</span> <span class="dv">10</span>)</span>
<span id="cb3-68"><a href="#cb3-68" aria-hidden="true" tabindex="-1"></a> modell.Maximize(x <span class="op">+</span> y)</span>
<span id="cb3-69"><a href="#cb3-69" aria-hidden="true" tabindex="-1"></a> loeser <span class="op">=</span> cp_model.CpSolver()</span>
<span id="cb3-70"><a href="#cb3-70" aria-hidden="true" tabindex="-1"></a> status <span class="op">=</span> loeser.Solve(modell)</span>
<span id="cb3-71"><a href="#cb3-71" aria-hidden="true" tabindex="-1"></a> ok <span class="op">=</span> status <span class="op">==</span> cp_model.OPTIMAL <span class="kw">and</span> loeser.Value(x) <span class="op">==</span> <span class="dv">4</span> <span class="kw">and</span> loeser.Value(y) <span class="op">==</span> <span class="dv">3</span></span>
<span id="cb3-72"><a href="#cb3-72" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;CP-SAT : x=</span><span class="sc">{</span>loeser<span class="sc">.</span>Value(x)<span class="sc">}</span><span class="ss">, y=</span><span class="sc">{</span>loeser<span class="sc">.</span>Value(y)<span class="sc">}</span><span class="ss"> -&gt; </span><span class="sc">{</span><span class="st">&#39;OK&#39;</span> <span class="cf">if</span> ok <span class="cf">else</span> <span class="st">&#39;FEHLER&#39;</span><span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-73"><a href="#cb3-73" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> ok</span>
<span id="cb3-74"><a href="#cb3-74" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-75"><a href="#cb3-75" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> teste_scipy_linprog() <span class="op">-&gt;</span> <span class="bu">bool</span>:</span>
<span id="cb3-76"><a href="#cb3-76" aria-hidden="true" tabindex="-1"></a> <span class="co">&quot;&quot;&quot;Löst dasselbe Problem kontinuierlich mit HiGHS über SciPy. Erwartet: x=4, y=3.&quot;&quot;&quot;</span></span>
<span id="cb3-77"><a href="#cb3-77" aria-hidden="true" tabindex="-1"></a> <span class="im">from</span> scipy.optimize <span class="im">import</span> linprog</span>
<span id="cb3-78"><a href="#cb3-78" aria-hidden="true" tabindex="-1"></a> <span class="co"># linprog minimiert -&gt; Zielfunktion negieren, um zu maximieren</span></span>
<span id="cb3-79"><a href="#cb3-79" aria-hidden="true" tabindex="-1"></a> ergebnis <span class="op">=</span> linprog(c<span class="op">=</span>[<span class="op">-</span><span class="dv">1</span>, <span class="op">-</span><span class="dv">1</span>], A_ub<span class="op">=</span>[[<span class="dv">1</span>, <span class="dv">2</span>]], b_ub<span class="op">=</span>[<span class="dv">10</span>],</span>
<span id="cb3-80"><a href="#cb3-80" aria-hidden="true" tabindex="-1"></a> bounds<span class="op">=</span>[(<span class="dv">0</span>, <span class="dv">4</span>), (<span class="dv">0</span>, <span class="dv">10</span>)], method<span class="op">=</span><span class="st">&quot;highs&quot;</span>)</span>
<span id="cb3-81"><a href="#cb3-81" aria-hidden="true" tabindex="-1"></a> ok <span class="op">=</span> ergebnis.success <span class="kw">and</span> <span class="bu">abs</span>(ergebnis.x[<span class="dv">0</span>] <span class="op">-</span> <span class="dv">4</span>) <span class="op">&lt;</span> <span class="fl">1e-6</span> <span class="kw">and</span> <span class="bu">abs</span>(ergebnis.x[<span class="dv">1</span>] <span class="op">-</span> <span class="dv">3</span>) <span class="op">&lt;</span> <span class="fl">1e-6</span></span>
<span id="cb3-82"><a href="#cb3-82" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;SciPy/HiGHS : x=</span><span class="sc">{</span>ergebnis<span class="sc">.</span>x[<span class="dv">0</span>]<span class="sc">:.2f}</span><span class="ss">, y=</span><span class="sc">{</span>ergebnis<span class="sc">.</span>x[<span class="dv">1</span>]<span class="sc">:.2f}</span><span class="ss"> -&gt; </span><span class="sc">{</span><span class="st">&#39;OK&#39;</span> <span class="cf">if</span> ok <span class="cf">else</span> <span class="st">&#39;FEHLER&#39;</span><span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-83"><a href="#cb3-83" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> ok</span>
<span id="cb3-84"><a href="#cb3-84" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-85"><a href="#cb3-85" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> teste_cvxpy() <span class="op">-&gt;</span> <span class="bu">bool</span>:</span>
<span id="cb3-86"><a href="#cb3-86" aria-hidden="true" tabindex="-1"></a> <span class="co">&quot;&quot;&quot;Minimiert (x-2)^2 unter x&lt;=1 mit CVXPY. Erwartet: x=1.&quot;&quot;&quot;</span></span>
<span id="cb3-87"><a href="#cb3-87" aria-hidden="true" tabindex="-1"></a> <span class="co"># CVXPY warnt beim Import, wenn sein HIGHS-Interface wegen der</span></span>
<span id="cb3-88"><a href="#cb3-88" aria-hidden="true" tabindex="-1"></a> <span class="co"># HiGHS-Kollision (siehe Kapitel Ökosystem) nicht lädt — für diesen Test</span></span>
<span id="cb3-89"><a href="#cb3-89" aria-hidden="true" tabindex="-1"></a> <span class="co"># folgenlos, deshalb die Warnung kurz stillstellen.</span></span>
<span id="cb3-90"><a href="#cb3-90" aria-hidden="true" tabindex="-1"></a> logging.disable(logging.WARNING)</span>
<span id="cb3-91"><a href="#cb3-91" aria-hidden="true" tabindex="-1"></a> <span class="im">import</span> cvxpy <span class="im">as</span> cp</span>
<span id="cb3-92"><a href="#cb3-92" aria-hidden="true" tabindex="-1"></a> logging.disable(logging.NOTSET)</span>
<span id="cb3-93"><a href="#cb3-93" aria-hidden="true" tabindex="-1"></a> x <span class="op">=</span> cp.Variable()</span>
<span id="cb3-94"><a href="#cb3-94" aria-hidden="true" tabindex="-1"></a> problem <span class="op">=</span> cp.Problem(cp.Minimize(cp.square(x <span class="op">-</span> <span class="dv">2</span>)), [x <span class="op">&lt;=</span> <span class="dv">1</span>])</span>
<span id="cb3-95"><a href="#cb3-95" aria-hidden="true" tabindex="-1"></a> problem.solve()</span>
<span id="cb3-96"><a href="#cb3-96" aria-hidden="true" tabindex="-1"></a> ok <span class="op">=</span> problem.status <span class="op">==</span> <span class="st">&quot;optimal&quot;</span> <span class="kw">and</span> <span class="bu">abs</span>(x.value <span class="op">-</span> <span class="fl">1.0</span>) <span class="op">&lt;</span> <span class="fl">1e-6</span></span>
<span id="cb3-97"><a href="#cb3-97" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;CVXPY : x=</span><span class="sc">{</span>x<span class="sc">.</span>value<span class="sc">:.4f}</span><span class="ss"> -&gt; </span><span class="sc">{</span><span class="st">&#39;OK&#39;</span> <span class="cf">if</span> ok <span class="cf">else</span> <span class="st">&#39;FEHLER&#39;</span><span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-98"><a href="#cb3-98" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> ok</span>
<span id="cb3-99"><a href="#cb3-99" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-100"><a href="#cb3-100" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</span>
<span id="cb3-101"><a href="#cb3-101" aria-hidden="true" tabindex="-1"></a> <span class="co"># ortools&#39; native Bibliothek zuerst laden (Kapitel Ökosystem): die zuerst</span></span>
<span id="cb3-102"><a href="#cb3-102" aria-hidden="true" tabindex="-1"></a> <span class="co"># geladene HiGHS-Kopie gewinnt — und das soll die von ortools sein.</span></span>
<span id="cb3-103"><a href="#cb3-103" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> importlib.util.find_spec(<span class="st">&quot;ortools&quot;</span>) <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span>:</span>
<span id="cb3-104"><a href="#cb3-104" aria-hidden="true" tabindex="-1"></a> <span class="im">from</span> ortools.sat.python <span class="im">import</span> cp_model</span>
<span id="cb3-105"><a href="#cb3-105" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-106"><a href="#cb3-106" aria-hidden="true" tabindex="-1"></a> fehlend <span class="op">=</span> pruefe_pakete()</span>
<span id="cb3-107"><a href="#cb3-107" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;</span><span class="ch">\n</span><span class="st">Solver-Funktionstest&quot;</span>)</span>
<span id="cb3-108"><a href="#cb3-108" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;-&quot;</span> <span class="op">*</span> <span class="dv">78</span>)</span>
<span id="cb3-109"><a href="#cb3-109" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> fehlend:</span>
<span id="cb3-110"><a href="#cb3-110" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f&quot;Abbruch: Es fehlen </span><span class="sc">{</span><span class="bu">len</span>(fehlend)<span class="sc">}</span><span class="ss"> Pakete: </span><span class="sc">{</span><span class="st">&#39;, &#39;</span><span class="sc">.</span>join(fehlend)<span class="sc">}</span><span class="ss">&quot;</span>)</span>
<span id="cb3-111"><a href="#cb3-111" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;Installation: pip install &quot;</span> <span class="op">+</span> <span class="st">&quot; &quot;</span>.join(</span>
<span id="cb3-112"><a href="#cb3-112" aria-hidden="true" tabindex="-1"></a> <span class="st">&quot;scikit-learn&quot;</span> <span class="cf">if</span> p <span class="op">==</span> <span class="st">&quot;sklearn&quot;</span> <span class="cf">else</span> p <span class="cf">for</span> p <span class="kw">in</span> fehlend))</span>
<span id="cb3-113"><a href="#cb3-113" aria-hidden="true" tabindex="-1"></a> sys.exit(<span class="dv">1</span>)</span>
<span id="cb3-114"><a href="#cb3-114" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-115"><a href="#cb3-115" aria-hidden="true" tabindex="-1"></a> alle_ok <span class="op">=</span> <span class="bu">all</span>([teste_cp_sat(), teste_scipy_linprog(), teste_cvxpy()])</span>
<span id="cb3-116"><a href="#cb3-116" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;-&quot;</span> <span class="op">*</span> <span class="dv">78</span>)</span>
<span id="cb3-117"><a href="#cb3-117" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">&quot;Alles bereit — Sie können mit dem ersten Kapitel beginnen.&quot;</span></span>
<span id="cb3-118"><a href="#cb3-118" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> alle_ok <span class="cf">else</span> <span class="st">&quot;Mindestens ein Solver arbeitet fehlerhaft.&quot;</span>)</span>
<span id="cb3-119"><a href="#cb3-119" aria-hidden="true" tabindex="-1"></a> sys.exit(<span class="dv">0</span> <span class="cf">if</span> alle_ok <span class="cf">else</span> <span class="dv">1</span>)</span></code></pre></div>
<p><strong>Erwartete Ausgabe (Versionsnummern können abweichen):</strong></p>
<pre><code>Python-Version: 3.12.3
Paket Version Zweck
------------------------------------------------------------------------------
numpy 2.1.3 Numerische Basis (Vektoren, Matrizen)
scipy 1.14.1 Wissenschaftliche Algorithmen, linprog/minimize
...
Solver-Funktionstest
------------------------------------------------------------------------------
CP-SAT : x=4, y=3 -&gt; OK
SciPy/HiGHS : x=4.00, y=3.00 -&gt; OK
CVXPY : x=1.0000 -&gt; OK
------------------------------------------------------------------------------
Alles bereit — Sie können mit dem ersten Kapitel beginnen.</code></pre>
<blockquote>
<p><strong>Hinweis zur Reproduzierbarkeit:</strong> Die Programme aus <a href="bruecke.html#teil-anwendungen">Teil IV</a> (<a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a> bis <a href="handelsmaschine.html#kap-handelsmaschine">Kapitel 21</a>) laden aktuelle Kursdaten live über <code>yfinance</code>. Die im Buchtext abgedruckten Zahlen dienen daher nur zur Illustration — bei eigenem Ausführen weichen sie je nach Abrufdatum und gewähltem Zeitfenster ab. Das ist beabsichtigt und selbst Teil der Lektion über die Instabilität empirischer Schätzungen (<a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a>).</p>
</blockquote>
<hr />
<h2 class="unnumbered" id="wie-dieses-buch-aufgebaut-ist">Wie dieses Buch aufgebaut ist</h2>
<p>Jedes Kapitel folgt derselben Struktur. Wenn Sie wissen, wie die Bausteine funktionieren, können Sie gezielt springen.</p>
<h3 class="unnumbered" id="die-lernelemente">Die Lernelemente</h3>
<blockquote>
<p><strong>Kapitel auf einen Blick</strong> Zu Beginn jedes Kapitels: Worum geht es, was wird vorausgesetzt, was können Sie danach, wie lange dauert es. Nutzen Sie diese Box, um zu entscheiden, ob Sie das Kapitel gerade brauchen.</p>
</blockquote>
<blockquote>
<p><strong>📐 Formel-Lesehilfe</strong> Steht unter jeder wichtigen Formel und benennt jedes Symbol einzeln, gefolgt von einer Umschreibung in Alltagssprache („Ohne Formel gesagt: …“). Wer die Formel schon versteht, überspringt die Box.</p>
</blockquote>
<blockquote>
<p><strong>✏️ Handrechnung</strong> Ein kleines Zahlenbeispiel, das Sie mit Papier und Bleistift nachvollziehen können — ohne Computer. Diese Rechnungen sind bewusst winzig gehalten, damit der Mechanismus sichtbar wird, den der Solver später millionenfach ausführt.</p>
</blockquote>
<blockquote>
<p><strong>💻 Code-Durchgang</strong> Nach jedem längeren Programm eine Tabelle, die die entscheidenden Zeilen erklärt. Vollständige Programme sind bewusst am Stück abgedruckt und nicht in Fragmente zerlegt — Sie sollen sie kopieren und laufen lassen können.</p>
</blockquote>
<blockquote>
<p><strong>⚠️ Typische Fehler</strong> Die Fallen, in die erfahrungsgemäß viele tappen — mit dem Symptom, das sie erzeugen, und der Korrektur.</p>
</blockquote>
<blockquote>
<p><strong>🎯 Merksatz</strong> Die eine Aussage, die vom Abschnitt hängen bleiben soll.</p>
</blockquote>
<blockquote>
<p><strong>📝 Übungsaufgaben</strong> Am Kapitelende, gestaffelt nach Schwierigkeit: ⭐ Verständnis (im Kopf oder in zwei Sätzen) · ⭐⭐ Handrechnung oder kleine Modelländerung · ⭐⭐⭐ Eigenständige Programmieraufgabe. <strong>Alle Lösungen</strong> stehen in <a href="anhang-loesungen.html"><code>90_Anhang_Loesungen.md</code></a>.</p>
</blockquote>
<blockquote>
<p><strong>✅ Selbsttest</strong> Fünf Fragen mit Kurzantworten zur schnellen Selbstkontrolle.</p>
</blockquote>
<h3 class="unnumbered" id="der-dreischritt-jedes-kapitels">Der Dreischritt jedes Kapitels</h3>
<ol type="1">
<li><strong>Problemstellung</strong> — eine konkrete Entscheidungssituation, kein abstraktes Beispiel.</li>
<li><strong>Mathematische Formulierung</strong> — mit Lesehilfe und, wo möglich, Handrechnung.</li>
<li><strong>Lauffähiges Python-Programm</strong> — vollständig abgedruckt, mit erwarteter Ausgabe.</li>
</ol>
<hr />
<h2 class="unnumbered" id="lernpfade">Lernpfade</h2>
<p>Sie müssen nicht alles lesen, um etwas Nützliches bauen zu können.</p>
<h3 class="unnumbered" id="pfad-a-vollständiger-lehrgang-100140-stunden">Pfad A — Vollständiger Lehrgang (100140 Stunden)</h3>
<p><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a> bis <a href="testing.html#kap-testing">Kapitel 23</a> in Reihenfolge, danach ein Projekt aus der Projektwerkstatt. Empfohlen, wenn Sie OR systematisch lernen wollen. Rechnen Sie mit 46 Stunden je Kapitel inklusive Übungen.</p>
<h3 class="unnumbered" id="pfad-b-planung-disposition-personaleinsatz-ca.-25-stunden">Pfad B — Planung, Disposition, Personaleinsatz (ca. 25 Stunden)</h3>
<p><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a> (Bausteine) → <a href="fundament.html#kap-fundament">Kapitel 2</a> (bis <a href="fundament.html#sec:fundament-konvexitaet-die-grenze-zwischen-leicht-und">Abschnitt 2.5</a>) → <a href="modellierung.html#kap-modellierung">Kapitel 4</a> (vom Wunsch zum Modell) → <a href="lp.html#kap-lp">Kapitel 5</a> (LP, Schattenpreise) → <a href="milp.html#kap-milp">Kapitel 6</a> (Ja/Nein-Entscheidungen) → <a href="cpsat.html#kap-cpsat">Kapitel 7</a> (CP-SAT, Scheduling) → Projekt <strong>P1</strong> (Vertretungsplaner) oder <strong>P2</strong> (Schichtplanung). Das ist der kürzeste Weg zu einem einsetzbaren Dienstplan-Optimierer.</p>
<p><em>Wenn der Solver bei Ihrer echten Instanz stehen bleibt:</em> <a href="metaheuristiken.html#kap-metaheuristiken">Kapitel 9</a> und Projekt <strong>P9</strong>.</p>
<h3 class="unnumbered" id="pfad-c-logistik-und-tourenplanung-ca.-25-stunden">Pfad C — Logistik und Tourenplanung (ca. 25 Stunden)</h3>
<p><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a><a href="fundament.html#kap-fundament">Kapitel 2</a> (bis <a href="fundament.html#sec:fundament-der-zulaessige-loesungsraum-und-das-polyeder">Abschnitt 2.4</a>) → <a href="lp.html#kap-lp">Kapitel 5</a><a href="milp.html#kap-milp">Kapitel 6</a><a href="graphen.html#kap-graphen">Kapitel 8</a> (Graphen, VRP) → Projekt <strong>P3</strong> (Liefertouren) oder <strong>P4</strong> (Lagernetzwerk).</p>
<p><em>Wenn die Instanzen zu groß werden:</em> <a href="metaheuristiken.html#kap-metaheuristiken">Kapitel 9</a> (gute Lösung in fester Zeit) und <a href="dekomposition.html#kap-dekomposition">Kapitel 10</a> (das Modell umbauen statt die Lösung raten) — dazu Projekt <strong>P9</strong>, das beide Wege am selben Problem vergleicht.</p>
<h3 class="unnumbered" id="pfad-d-quantitative-finance-ca.-30-stunden">Pfad D — Quantitative Finance (ca. 30 Stunden)</h3>
<p><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a><a href="fundament.html#kap-fundament">Kapitel 2</a><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a> (QP, KKT) → <a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a> (Daten, Shrinkage) → <a href="markowitz.html#kap-markowitz">Kapitel 19</a> (Markowitz) → <a href="cvar.html#kap-cvar">Kapitel 20</a> (CVaR) → <a href="handelsmaschine.html#kap-handelsmaschine">Kapitel 21</a> (Backtest) → Projekt <strong>P6</strong> (Portfolio-Rebalancer) oder <strong>P7</strong> (Risikoreport). <strong>Wichtig:</strong> Überspringen Sie <a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a> nicht. Wer direkt bei Markowitz einsteigt, optimiert Schätzrauschen und wundert sich über absurde Gewichte.</p>
<h3 class="unnumbered" id="pfad-e-ich-habe-morgen-ein-konkretes-problem-24-stunden">Pfad E — Ich habe morgen ein konkretes Problem (24 Stunden)</h3>
<p>Lesen Sie <a href="einfuehrung.html#sec:einfuehrung-historischer-kontext-und-evolution">Abschnitt 1.5</a> (die vier Bausteine), dann <a href="anhang-modellierungsmuster.html#anhang-modellierungsmuster">Anhang B</a> (<a href="anhang-modellierungsmuster.html">Modellierungsmuster</a>) und suchen Sie dort das Muster, das zu Ihrem Problem passt. Von jedem Muster führt ein Verweis in das zuständige Kapitel. Wie die gewählte Bibliothek es schreibt, steht in <a href="anhang-spickzettel.html#anhang-spickzettel">Anhang D</a> (<a href="anhang-spickzettel.html">Spickzettel</a>); wenn etwas nicht läuft, in <a href="anhang-fehlerdiagnose.html#anhang-fehlerdiagnose">Anhang C</a> (<a href="anhang-fehlerdiagnose.html">Fehlerdiagnose</a>).</p>
<h3 class="unnumbered" id="pfad-f-vom-prototyp-in-den-betrieb-ca.-15-stunden">Pfad F — Vom Prototyp in den Betrieb (ca. 15 Stunden)</h3>
<p>Für alle, deren Modell <strong>rechnet</strong> und die es jetzt jemand anderem übergeben müssen: <a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a> (die fünf Praxisfallen, <code>or_kern.py</code>, Erklärbarkeit) → <a href="testing.html#kap-testing">Kapitel 23</a> (Testsuite, Mutationstest, Benchmark, HTTP-Dienst) → <a href="anhang-fehlerdiagnose.html#anhang-fehlerdiagnose">Anhang C</a> als Nachschlagewerk für den Ernstfall, dann Projekt <strong>P11</strong> (Vom Skript zum Dienst). Setzt voraus, dass Sie mindestens einen der Pfade B, C oder D hinter sich haben — P11 baut auf einem Modell auf, das Sie schon haben.</p>
<p><em>Der Kern in einem Satz:</em> Ein Modell, das nur auf Ihrem Rechner und nur mit Ihren Daten läuft, ist ein Prototyp — kein System.</p>
<hr />
<h2 class="unnumbered" id="verzeichnis-der-beispielprogramme">Verzeichnis der Beispielprogramme</h2>
<p>Alle Beispielprogramme dieses Buchs im Überblick, sortiert nach Kapitel — praktisch für Pfad E oder um gezielt nach einem Thema zu suchen:</p>
<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="header">
<th>Programm</th>
<th>Thema</th>
<th>Kapitel</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><code>Installationstest.py</code></td>
<td>Installationsprüfung</td>
<td>Vorspann</td>
</tr>
<tr class="even">
<td><code>Bot_Allokation.py</code></td>
<td>Erstes CP-SAT-Modell</td>
<td><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a></td>
</tr>
<tr class="odd">
<td><code>Brute_Force_Vergleich.py</code></td>
<td>Kombinatorische Explosion</td>
<td><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a></td>
</tr>
<tr class="even">
<td><code>Bausteine_Vorlage.py</code></td>
<td>Vorlage für eigene Modelle</td>
<td><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a></td>
</tr>
<tr class="odd">
<td><code>Excel_Bruecke.py</code></td>
<td>Excel-Mappe lesen, lösen, zurückschreiben</td>
<td><a href="einfuehrung.html#kap-einfuehrung">Kapitel 1</a></td>
</tr>
<tr class="even">
<td><code>Matrixform.py</code></td>
<td>Matrixform und Zulässigkeit</td>
<td><a href="fundament.html#kap-fundament">Kapitel 2</a></td>
</tr>
<tr class="odd">
<td><code>Konvexitaet_Demo.py</code></td>
<td>Sehnen-Test, lokale Optima</td>
<td><a href="fundament.html#kap-fundament">Kapitel 2</a></td>
</tr>
<tr class="even">
<td><code>Visualisierung_Loesungsraum.py</code></td>
<td>Polyeder mit Ecken</td>
<td><a href="fundament.html#kap-fundament">Kapitel 2</a></td>
</tr>
<tr class="odd">
<td><code>Skalierung_Kondition.py</code></td>
<td>Konditionszahl, Ruiz, Toleranzen</td>
<td><a href="fundament.html#kap-fundament">Kapitel 2</a></td>
</tr>
<tr class="even">
<td><code>Solver_Wahl.py</code></td>
<td>Entscheidungshilfe</td>
<td><a href="oekosystem.html#kap-oekosystem">Kapitel 3</a></td>
</tr>
<tr class="odd">
<td><code>Ein_System_Vier_Ansaetze.py</code></td>
<td>Vier Bibliotheken</td>
<td><a href="oekosystem.html#kap-oekosystem">Kapitel 3</a></td>
</tr>
<tr class="even">
<td><code>Modellierungsschichten.py</code></td>
<td>Pyomo und Linopy</td>
<td><a href="oekosystem.html#kap-oekosystem">Kapitel 3</a></td>
</tr>
<tr class="odd">
<td><code>Vektorisierte_Modellgenerierung.py</code></td>
<td>Aufbauzeit vs. Lösezeit</td>
<td><a href="oekosystem.html#kap-oekosystem">Kapitel 3</a></td>
</tr>
<tr class="even">
<td><code>Vom_Wunsch_zum_Modell.py</code></td>
<td>Fünf Modelle auf denselben Daten</td>
<td><a href="modellierung.html#kap-modellierung">Kapitel 4</a></td>
</tr>
<tr class="odd">
<td><code>Simplex_Tableau_LP.py</code></td>
<td>Simplex von Grund auf</td>
<td><a href="lp.html#kap-lp">Kapitel 5</a></td>
</tr>
<tr class="even">
<td><code>Sensitivitaetsanalyse.py</code></td>
<td>Schattenpreise</td>
<td><a href="lp.html#kap-lp">Kapitel 5</a></td>
</tr>
<tr class="odd">
<td><code>Dualitaet_Nachweis.py</code></td>
<td>Primal-dual, starke Dualität</td>
<td><a href="lp.html#kap-lp">Kapitel 5</a></td>
</tr>
<tr class="even">
<td><code>Toleranzen_und_Entartung.py</code></td>
<td>Entartung, Toleranzen, Dualspannen</td>
<td><a href="lp.html#kap-lp">Kapitel 5</a></td>
</tr>
<tr class="odd">
<td><code>Runden_Gegenbeispiel.py</code></td>
<td>Warum Runden scheitert</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="even">
<td><code>Rucksack.py</code></td>
<td>Knapsack, LP-Schranke</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="odd">
<td><code>MILP_Portfolio_Fixgebuehren.py</code></td>
<td>Fixkosten, Kardinalität</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="even">
<td><code>Solverstatus_und_Gap.py</code></td>
<td>MIP-Gap, Zeitlimit, Statusfälle</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="odd">
<td><code>Warmstart_Effekt.py</code></td>
<td>LPT-Hinweis für CP-SAT</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="even">
<td><code>Big_M_Falle.py</code></td>
<td>Trickle Flow bei zu großem M</td>
<td><a href="milp.html#kap-milp">Kapitel 6</a></td>
</tr>
<tr class="odd">
<td><code>Propagation_Demo.py</code></td>
<td>Propagation messbar</td>
<td><a href="cpsat.html#kap-cpsat">Kapitel 7</a></td>
</tr>
<tr class="even">
<td><code>CP_SAT_Vertretungssystem.py</code></td>
<td>Vertretungsplan</td>
<td><a href="cpsat.html#kap-cpsat">Kapitel 7</a></td>
</tr>
<tr class="odd">
<td><code>JobShop_Intervalle.py</code></td>
<td>Job-Shop-Scheduling</td>
<td><a href="cpsat.html#kap-cpsat">Kapitel 7</a></td>
</tr>
<tr class="even">
<td><code>CP_SAT_Statusfaelle.py</code></td>
<td>Die fünf Solver-Antworten</td>
<td><a href="cpsat.html#kap-cpsat">Kapitel 7</a></td>
</tr>
<tr class="odd">
<td><code>Strafgewichte.py</code></td>
<td>Gewichte als Wechselkurse</td>
<td><a href="cpsat.html#kap-cpsat">Kapitel 7</a></td>
</tr>
<tr class="even">
<td><code>Min_Cost_Flow.py</code></td>
<td>Netzwerkfluss</td>
<td><a href="graphen.html#kap-graphen">Kapitel 8</a></td>
</tr>
<tr class="odd">
<td><code>Zuordnung_Ungarisch.py</code></td>
<td>Zuordnung, Unimodularität</td>
<td><a href="graphen.html#kap-graphen">Kapitel 8</a></td>
</tr>
<tr class="even">
<td><code>VRP_Flotten_Routing.py</code></td>
<td>CVRPTW</td>
<td><a href="graphen.html#kap-graphen">Kapitel 8</a></td>
</tr>
<tr class="odd">
<td><code>VRP_Kapazitaetsfalle.py</code></td>
<td>Vergessene Dimension im Routing</td>
<td><a href="graphen.html#kap-graphen">Kapitel 8</a></td>
</tr>
<tr class="even">
<td><code>Simulated_Annealing.py</code></td>
<td>Lokale Suche, Temperatur kalibrieren</td>
<td><a href="metaheuristiken.html#kap-metaheuristiken">Kapitel 9</a></td>
</tr>
<tr class="odd">
<td><code>Metaheuristik_vs_Exakt.py</code></td>
<td>Der Umschlagpunkt, und die Schranke</td>
<td><a href="metaheuristiken.html#kap-metaheuristiken">Kapitel 9</a></td>
</tr>
<tr class="even">
<td><code>Large_Neighborhood_Search.py</code></td>
<td>Zerstören und exakt reparieren</td>
<td><a href="metaheuristiken.html#kap-metaheuristiken">Kapitel 9</a></td>
</tr>
<tr class="odd">
<td><code>Spaltengenerierung.py</code></td>
<td>Muster statt Stücke, Master und Pricing</td>
<td><a href="dekomposition.html#kap-dekomposition">Kapitel 10</a></td>
</tr>
<tr class="even">
<td><code>QP_Grundlagen.py</code></td>
<td>Konvexität, DCP-Check</td>
<td><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a></td>
</tr>
<tr class="odd">
<td><code>KKT_Nachweis.py</code></td>
<td>KKT numerisch prüfen</td>
<td><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a></td>
</tr>
<tr class="even">
<td><code>Entropie_Maximierte_Allokation.py</code></td>
<td>NLP mit Entropie</td>
<td><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a></td>
</tr>
<tr class="odd">
<td><code>Lokale_Optima_Multistart.py</code></td>
<td>Lokale Optima, Multistart</td>
<td><a href="qp-nlp.html#kap-qp-nlp">Kapitel 11</a></td>
</tr>
<tr class="even">
<td><code>Fluch_des_Durchschnitts.py</code></td>
<td>Optimum ≠ Mittelwert</td>
<td><a href="unsicherheit.html#kap-unsicherheit">Kapitel 12</a></td>
</tr>
<tr class="odd">
<td><code>Monte_Carlo.py</code></td>
<td>Monte-Carlo-Bewertung</td>
<td><a href="unsicherheit.html#kap-unsicherheit">Kapitel 12</a></td>
</tr>
<tr class="even">
<td><code>Stochastische_Optimierung.py</code></td>
<td>Two-Stage mit Recourse</td>
<td><a href="unsicherheit.html#kap-unsicherheit">Kapitel 12</a></td>
</tr>
<tr class="odd">
<td><code>Robuste_Optimierung.py</code></td>
<td>Worst-Case-Absicherung</td>
<td><a href="unsicherheit.html#kap-unsicherheit">Kapitel 12</a></td>
</tr>
<tr class="even">
<td><code>Bellman_Minimalbeispiel.py</code></td>
<td>Rückwärtsinduktion</td>
<td><a href="dynamische-programmierung.html#kap-dynamische-programmierung">Kapitel 13</a></td>
</tr>
<tr class="odd">
<td><code>Mehrziel_Pareto.py</code></td>
<td>Pareto-Front, ε-Constraint, Gewichtslücke</td>
<td><a href="mehrziel.html#kap-mehrziel">Kapitel 14</a></td>
</tr>
<tr class="even">
<td><code>Predict_then_Optimize.py</code></td>
<td>MSE gegen Entscheidungskosten</td>
<td><a href="prognose.html#kap-prognose">Kapitel 15</a></td>
</tr>
<tr class="odd">
<td><code>Strukturbruecke.py</code></td>
<td>Derselbe Code über Werkstatt und Depot</td>
<td><a href="bruecke.html#kap-bruecke">Kapitel 16</a></td>
</tr>
<tr class="even">
<td><code>Kraftwerkseinsatz.py</code></td>
<td>Unit Commitment unter Windunsicherheit</td>
<td><a href="supplychain.html#kap-supplychain">Kapitel 17</a></td>
</tr>
<tr class="odd">
<td><code>Mehrperiodige_Order_Execution.py</code></td>
<td>Almgren-Chriss</td>
<td><a href="dynamische-programmierung.html#kap-dynamische-programmierung">Kapitel 13</a></td>
</tr>
<tr class="even">
<td><code>Renditen_Vergleich.py</code></td>
<td>Diskret vs. logarithmisch</td>
<td><a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a></td>
</tr>
<tr class="odd">
<td><code>Schaetzrauschen_Demo.py</code></td>
<td>Error-Maximizer messen</td>
<td><a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a></td>
</tr>
<tr class="even">
<td><code>Finanzdaten_Ledoit_Wolf.py</code></td>
<td>Datenpipeline, Shrinkage</td>
<td><a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a></td>
</tr>
<tr class="odd">
<td><code>Kovarianz_Falle.py</code></td>
<td>Singuläre Kovarianz, Error-Maximizer</td>
<td><a href="finanzdaten.html#kap-finanzdaten">Kapitel 18</a></td>
</tr>
<tr class="even">
<td><code>Markowitz_CVXPY.py</code></td>
<td>GMV, Max Sharpe, Frontier</td>
<td><a href="markowitz.html#kap-markowitz">Kapitel 19</a></td>
</tr>
<tr class="odd">
<td><code>Diversifikation_Demo.py</code></td>
<td>Korrelation und Portfoliorisiko</td>
<td><a href="markowitz.html#kap-markowitz">Kapitel 19</a></td>
</tr>
<tr class="even">
<td><code>Renditeschaetzung_Falle.py</code></td>
<td>Schätzfehler in erwarteten Renditen</td>
<td><a href="markowitz.html#kap-markowitz">Kapitel 19</a></td>
</tr>
<tr class="odd">
<td><code>VaR_CVaR_Demo.py</code></td>
<td>Fat Tails, Subadditivität</td>
<td><a href="cvar.html#kap-cvar">Kapitel 20</a></td>
</tr>
<tr class="even">
<td><code>CVaR_Portfolio.py</code></td>
<td>CVaR mit Reibung</td>
<td><a href="cvar.html#kap-cvar">Kapitel 20</a></td>
</tr>
<tr class="odd">
<td><code>QuantitativeTradingEngine.py</code></td>
<td>Walk-Forward-Backtest</td>
<td><a href="handelsmaschine.html#kap-handelsmaschine">Kapitel 21</a></td>
</tr>
<tr class="even">
<td><code>Backtest_Fallen.py</code></td>
<td>Fünf Selbsttäuschungen</td>
<td><a href="handelsmaschine.html#kap-handelsmaschine">Kapitel 21</a></td>
</tr>
<tr class="odd">
<td><code>Data_Snooping.py</code></td>
<td>Bestes aus N Versuchen auf Rauschen</td>
<td><a href="handelsmaschine.html#kap-handelsmaschine">Kapitel 21</a></td>
</tr>
<tr class="even">
<td><code>Infeasibility_Diagnose.py</code></td>
<td>Notfallplan statt Fehler</td>
<td><a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a></td>
</tr>
<tr class="odd">
<td><code>Erklaerbarkeit.py</code></td>
<td>Constraint-Trace, Was-wäre-wenn</td>
<td><a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a></td>
</tr>
<tr class="even">
<td><code>Betriebsueberwachung.py</code></td>
<td>Status, Gap und Zeitausschöpfung</td>
<td><a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a></td>
</tr>
<tr class="odd">
<td><code>or_kern.py</code></td>
<td>Gemeinsamer Unterbau: Domäne, Status, Prüfung</td>
<td><a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a></td>
</tr>
<tr class="even">
<td><code>Solverwechsel_CPSAT_HiGHS.py</code></td>
<td>Derselbe Fall in zwei Solvern</td>
<td><a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a></td>
</tr>
<tr class="odd">
<td><code>test_or_kern.py</code></td>
<td>Testsuite für ein Optimierungsmodell</td>
<td><a href="testing.html#kap-testing">Kapitel 23</a></td>
</tr>
<tr class="even">
<td><code>Mutationstest.py</code></td>
<td>Findet die Lücken der eigenen Tests</td>
<td><a href="testing.html#kap-testing">Kapitel 23</a></td>
</tr>
<tr class="odd">
<td><code>Benchmark_Skalierung.py</code></td>
<td>Aufbau gegen Lösen, vier Bibliotheken</td>
<td><a href="testing.html#kap-testing">Kapitel 23</a></td>
</tr>
<tr class="even">
<td><code>Optimierungsdienst.py</code></td>
<td>Das Modell als HTTP-Dienst</td>
<td><a href="testing.html#kap-testing">Kapitel 23</a></td>
</tr>
<tr class="odd">
<td><code>Konfliktsuche.py</code></td>
<td>Deletion Filter: den Widerspruch einkreisen</td>
<td><a href="anhang-fehlerdiagnose.html#anhang-fehlerdiagnose">Anhang C</a></td>
</tr>
</tbody>
</table>
<hr />
<h2 class="unnumbered" id="was-dieses-buch-nicht-ist">Was dieses Buch nicht ist</h2>
<p>Es ist <strong>keine Anleitung zum Bau eigener Solver</strong> — wir nutzen ausgereifte Implementierungen und investieren die Zeit stattdessen in die Modellierung. Die einzige Ausnahme ist der Simplex-Algorithmus in <a href="lp.html#kap-lp">Kapitel 5</a>, den wir von Grund auf programmieren, weil man ihn verstanden haben muss, um Dualität und Schattenpreise zu begreifen.</p>
<p>Es ist <strong>kein Buch über maschinelles Lernen</strong>. Prognosen kommen nur so weit vor, wie sie als Eingangsdaten einer Optimierung nötig sind.</p>
<p>Und der vierte Teil ist <strong>ausdrücklich keine Anlageberatung</strong>. Die Finanzbeispiele demonstrieren Methodik an realen Daten, nicht handelbare Strategien. <a href="praxisfallen.html#kap-praxisfallen">Kapitel 22</a> erklärt ausführlich, warum ein gut aussehender Backtest noch keine funktionierende Strategie ist.</p>
<hr />
<h2 class="unnumbered" id="ein-wort-zur-arbeitsweise">Ein Wort zur Arbeitsweise</h2>
<p>Die wirksamste Art, mit diesem Buch zu arbeiten, ist unbequem: <strong>Lesen Sie die Problemstellung, schließen Sie das Buch und versuchen Sie, das Modell selbst aufzuschreiben</strong> — Variablen, Zielfunktion, Nebenbedingungen. Vergleichen Sie erst dann. Die Abweichungen zwischen Ihrem Entwurf und dem Text sind genau die Stellen, an denen Sie etwas lernen. Wer stattdessen mitliest und nickt, hat am Ende des Kapitels das angenehme Gefühl, es verstanden zu haben — und steht beim eigenen Problem vor einem leeren Blatt.</p>
<p>Zweitens: <strong>Lassen Sie jedes Programm laufen und verändern Sie danach eine Zahl.</strong> Was passiert mit dem Vertretungsplan, wenn eine Lehrkraft ausfällt? Was mit dem Portfolio, wenn die Obergrenze von 20 % auf 10 % sinkt? Diese Experimente kosten Sekunden und bauen genau die Intuition auf, die man später beim Modellieren braucht.</p>
<p>Und drittens: <strong>Nehmen Sie die Übungen ernst.</strong> Sie sind nicht Beiwerk, sondern der Ort, an dem aus Kenntnis Können wird.</p>
<hr />
<p><em>Weiter mit:</em> <a href="notation.html"><code>01_Notation_und_Abkuerzungen.md</code></a> — oder direkt zu <a href="einfuehrung.html">[Kapitel 1](einfuehrung.html#kap-einfuehrung)</a>, wenn Sie die Notation lieber nachschlagen, sobald sie auftaucht.</p>
</article>
<nav class="prev-next"><span class="prev-next-leer"></span><a class="prev-next-knopf prev-next-next" href="notation.html"><span><small>Weiter</small>Notation & Abkürzungen</span><svg class="icon" aria-hidden="true"><use href="#icon-chevron-right"></use></svg></a></nav>
</main>
</div>
<footer class="site-footer">
<p>© Dieter Schlüter · <a href="gesamtdokument.html">Gesamtdokument</a> ·
<a href="programme.html">Beispielprogramme</a></p>
</footer>
<script defer src="assets/search-index.js"></script>
<script defer src="assets/programme.js"></script>
<script defer src="assets/site.js"></script>
</body>
</html>