• Keine Ergebnisse gefunden

Constraint-Programmierung Vorlesung Sommersemester 2009, 2012, 2015, WS 2016

N/A
N/A
Protected

Academic year: 2022

Aktie "Constraint-Programmierung Vorlesung Sommersemester 2009, 2012, 2015, WS 2016"

Copied!
12
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Constraint-Programmierung Vorlesung

Sommersemester 2009, 2012, 2015, WS 2016

Johannes Waldmann, HTWK Leipzig

13. Oktober 2016

(2)

Constraint-Programmierung—Beispiel

(set-logic QF_NIA)(set-option :produce-models true) (declare-fun P () Int) (declare-fun Q () Int)

(declare-fun R () Int) (declare-fun S () Int) (assert (and (< 0 P) (<= 0 Q) (< 0 R) (<= 0 S))) (assert (> (+ (* P S) Q) (+ (* R Q) S)))

(check-sat)(get-value (P Q R S))

I Constraint-System=eine pr ¨adikatenlogische FormelF

I L ¨osung=Modell vonF (=StrukurM, in derF wahr ist)

I CP ist eine Form derdeklarativenProgrammierung.

I Vorteil: Benutzung von allgemeinen Suchverfahren (bereichs-, aber nicht anwendungsspezifisch).

(3)

Industrielle Anwendungen der CP

I Verifikation von Schaltkreisen

(bevorman diese tats ¨achlich produziert)

F =S-Implementierung(x)6=S-Spezifikation(x)

wennF unerf ¨ullbar (¬∃x), dann Implementierung korrekt

I Verifikation von Software durchmodel checking:

Programmzust ¨ande abstrahieren durch Zustandspr ¨adikate, Programmabl ¨aufe durch endliche Automaten.

z. B. Static Driver Verifierhttp://research.

microsoft.com/en-us/projects/slam/

benutzt Constraint-Solver Z3http://research.

microsoft.com/en-us/um/redmond/projects/z3/

(4)

Industrielle Anwendungen der CP

automatische Analyse des Resourcenverbrauchs von Programmen

I Termination (jede Rechnung h ¨alt)

I Komplexit ¨at (. . . nachO(n2)Schritten) mittelsBewertungenvon Programmzust ¨anden:

I W :Zustandsmenge→N

I wennz1→z2, dannW(z1)>W(z2).

Parameter der Bewertung werden durch Constraint-System beschrieben.

(5)

CP-Anwendung: Polynom-Interpretationen

I Berechnungsmodell: Wortersetzung (≈Turingmaschine)

I Programm:ab →ba(≈Bubble-Sort)

Beispiel-Rechnung:abab→baab→baba→bbaa

I BewertungW durch lineare Funktionen

fa(x) =Px +Q,fb(x) =Rx +SmitP,Q,R,S∈N W(abab) =fa(fb(fa(fb(0)))), . . .

I monoton:x >y ⇒fa(x)>fa(y)∧fb(x)>fb(y)

I kompatibel mit Programm:fa(fb(x)>fb(fa(x))

I resultierendes Constraint-System f ¨urP,Q,R,S,

I L ¨osung mittels Z3

(6)

Wettbewerbe f ¨ur Constraint-Solver

I f ¨ur aussagenlogische Formeln:

http://www.satcompetition.org/

(SAT=satisfiability)

I f ¨ur pr ¨adikatenlogische Formeln

http://smtcomp.sourceforge.net/

(SMT=satisfiability modulo theories)

Theorien:Zmit≤, Plus, Mal;Rmit≤, Plus; . . .

I Termination und Komplexit ¨at

http://www.termination-portal.org/wiki/

Termination_Competition

(7)

Gliederung der Vorlesung

I Aussagenlogik

I CNF-SAT-Constraints (Normalf., Tseitin-Transformation)

I DPLL-Solver, Backtracking und Lernen

I ROBDDs (Entscheidungsdiagramme)

I Pr ¨adikatenlogik (konjunktive Constraints)

I Finite-Domain-Constraints

I naive L ¨osungsverfahren, Konsistenzbegriffe

I lineare Gleichungen, Ungleichungen, Polynomgleichungen

I Termgleichungen, Unifikation

I Kombinationen

I Kodierungen nach CNF-SAT (FD, Zahlen)

I SMT, DPLL(T)

(8)

Organisatorisches

I jede Woche 1 Vorlesung+1 ¨Ubung

I Ubungsaufgaben¨

I schriftlich“, d.h. Aufgabe im Skript (Folie), Diskussion in Ubung an der Tafel¨

I online, d.h. Aufgabe in|autotool—, Bearbeitung selbst ¨andig

Pr ¨ufungszulassung: 50 Prozent der autotool-Pflichtaufgaben

I Klausur (2 h, keine Hilfsmittel)

(9)

Literatur

I Krzysztof Apt:Principles of Constraint Programming, http://www.cambridge.org/catalogue/

catalogue.asp?isbn=9780521825832

I Daniel Kroening, Ofer Strichman:Decision Procedures, Springer 2008.

http://www.decision-procedures.org/

I Petra Hofstedt, Armin Wolf: Einf ¨uhrung in die Constraint-Programmierung, Springer 2007.

http://www.springerlink.com/content/

978-3-540-23184-4/

I Uwe Sch ¨oning: Logik f ¨ur Informatiker, Spektrum Akad.

Verlag, 2000.

(10)

Ausblick

ich betreue gern

Masterprojekte/-Arbeiten zur Constraint-Programmierung, z.B.

I Tests/Verbesserung f ¨ur

https://github.com/ekmett/ersatz

I Ersatz- ¨ahnliche Schnittstelle f ¨ur

https://github.com/adamwalker/haskell_cudd

I autotool-Aufgaben zu CP, vgl.https:

//gitlab.imn.htwk-leipzig.de/autotool/all/

tree/master/collection/src/DPLLT

I Anwendungen (auch: nichtlineare bzw. diskrete Optimierung, data mining)

(11)

Ubung KW41 (Aufgaben) ¨

I Constraint-Optimierungsprobleme:https://www.nada.

kth.se/˜viggo/problemlist/compendium.html Beispiel:https://www.nada.kth.se/˜viggo/

wwwcompendium/node195.html

I Beispiele f ¨ur Constraints aus der Unterhaltungsmathematik:

http://www.janko.at/Raetsel/,

http://www.nikoli.co.jp/en/puzzles/

I formales Modell f ¨ur

I http://www.janko.at/Raetsel/Sternenhaufen/

I http://www.janko.at/Raetsel/Wolkenkratzer/

I Constraint-Solver im Pool ausprobieren (Z3, minisat) allgemeine Hinweise:http://www.imn.

htwk-leipzig.de/˜waldmann/etc/pool/ http://

www.imn.htwk-leipzig.de/˜waldmann/etc/beam/

I autotool: einschreiben und ausprobieren

https://autotool.imn.htwk-leipzig.de/new/

vorlesung/234/aufgaben

(12)

Ubung KW41 (Diskussion) ¨

Constraint-System f ¨ur Hochhaus-R ¨atsel:

I Unbekannte:hx,y ∈ {0, . . . ,n−1}f ¨urx,y ∈ {0, . . . ,n−1}

I Constraint f ¨ur eine Zeilex: W

p∈Permutationen(0,...,n−1),pkompatibel mit Vorgaben

V

y∈{0,...,n−1}(hx,y = p(y))

Bsp:n=4, Vorgabe links 2, rechts 1, kompatibel sind [0,2,1,3],[2,0,1,3],[2,1,0,3],[2,1,0,3].

entspr. f ¨ur Spalten

I diese Formel wird exponentiell groß (wg. Anzahl Permutationen),

Folge-Aufgabe:geht das auch polynomiell?

Constraint f ¨ur monotone kompatible Bewertungsfunktion:

I mit Z3 l ¨osen

I eine kleinste L ¨osung finden (Summe vonP,Q,R,S m ¨oglichst klein) — daf ¨ur Assert(s) hinzuf ¨ugen.

I Abstieg der so gefundenen Bewertungsfunktion nachrechnen f ¨urabab→baab →baba→bbaa

I gibt diese Bewertungsfunktion die maximale Schrittzahl genau wieder? (nein)

I Folge-Aufgabe: entspr. Constraint-System f ¨ur

Bewertungsfunktion f ¨urab →bbaaufstellen und l ¨osen.

Referenzen

ÄHNLICHE DOKUMENTE

Zeichne alle Kanten ein, die benötigt werden, damit sich die von dem Automaten akzeptierte Sprache nicht ändert, wenn man die -Kante wegläÿt... deterministische

Automaten akzeptiert wird, gibt es eine rechts- lineare Grammatik, die diese Sprache erzeugt und umgekehrt8. A=

• Anwendungen: SAT-Kodierungen f¨ur kombinatorische Aufgaben, Bit-Blasting f¨ur andere Constraint-Bereiche Pr¨adikatenlogik: Bereiche und -spezifische Verfahren:. • finite

in Polynomialzeit eine Formel konstruieren, die genau dann erf ¨ullbar ist, wenn das Problem eine L ¨osung hat — und man kann aus der erf ¨ullenden Belegung eine L

in Polynomialzeit eine Formel konstruieren, die genau dann erf ¨ullbar ist, wenn das Problem eine L ¨osung hat — und man kann aus der erf ¨ullenden Belegung eine L

Johannes Waldmann, HTWK Leipzig () Deklarative (= fortgeschrittene) Programmierung Vorlesung WS 2009, WS 2010, SS 2012 25...

in Polynomialzeit eine Formel konstruieren, die genau dann erf ¨ullbar ist, wenn das Problem eine L ¨osung

I Klasse enth ¨alt zuviele Methoden Aufgabe: welche