34
"תתתתת תתתתתת "תתתת תתתת תתתתתתתת תתת תתתתתתת

תכנון ובעיות "קשות"

  • Upload
    diella

  • View
    54

  • Download
    0

Embed Size (px)

DESCRIPTION

תכנון ובעיות "קשות". בינה מלאכותית אבי רוזנפלד. יש בעיות שכנראה המחשב לא יכול לפתור. NP-Complete. P. NP. איך פותרים את הבעיה???. אין פתרון פולינומיאלי ! צריכים לבדוק כל אפשרות! BRUTE FORCE = n! תכנות דינאמי– "רק" n 2 2 n כנראה שאין פתרון "סביר" - פולינומיאלי. - PowerPoint PPT Presentation

Citation preview

Page 1: תכנון ובעיות "קשות"

"תכנון ובעיות "קשות

מלאכותית בינהרוזנפלד אבי

Page 2: תכנון ובעיות "קשות"

המחשב לא שכנראהיש בעיות יכול לפתור

PNP

NP-Complete

Page 3: תכנון ובעיות "קשות"
Page 4: תכנון ובעיות "קשות"
Page 5: תכנון ובעיות "קשות"

???איך פותרים את הבעיה

אין פתרון פולינומיאלי!•צריכים לבדוק כל אפשרות!••BRUTE FORCE = n!n22nתכנות דינאמי– "רק" •

כנראה שאין פתרון "סביר" - פולינומיאלי•

Page 6: תכנון ובעיות "קשות"

NP-Complete דוגמאות

•To prove a problem is NP-Complete show a polynomial time reduction from 3-SAT

•Other NP-Complete Problems:–PARTITION–SUBSET-SUM–CLIQUE–HAMILTONIAN PATH (TSP)–GRAPH COLORING–MINESWEEPER (and many more)

Page 7: תכנון ובעיות "קשות"

רוב בעיות של תכנון ואופטימיזציה !הם פה

Page 8: תכנון ובעיות "קשות"

NPרק הבעיות המעניות הם

• Deterministic Polynomial Time: The TM takes at most O(nc) steps to accept a string of length n

• Non-deterministic Polynomial Time: The TM takes at most O(nc) steps on each computation path to accept a string of length n

Page 9: תכנון ובעיות "קשות"

?אז מה עושים

•Branch and Bound כעין( PRUNING)•HILLCLIMING•HEURISTICS•Mixed Integer Programming

Page 10: תכנון ובעיות "קשות"

• Constraint Satisfaction Problems (CSP)• Constraint Optimization Problems (COP)• Backtracking search for CSP and COPs• Problem Structure and Problem

Decomposition• Local search for COPs

10

COP וCSPדוגמאות

Page 11: תכנון ובעיות "קשות"

• Variables WA, NT, Q, NSW, V, SA, T • Domains Di = {red, green, blue}• Constraints: adjacent regions must have different colors

e.g., WA ≠ NT (if the language allows stating this so succinctly), or(WA, NT) in {(red,green), (red,blue), (green,red), (green,blue), (blue,red), (blue,green)}

•11

Example: Map-Coloring

Page 12: תכנון ובעיות "קשות"

This is a solution: complete and consistent assignments (i.e., all variables assigned, all constraints satisfied):e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green•

12

Example: Map-Coloring

Page 13: תכנון ובעיות "קשות"

• Binary CSP: each constraint relates two variables• Constraint graph: nodes are variables, arcs show constraints

13

Constraint graph

General-purpose CSP algorithms use the graph structure to speed up search, e.g., Tasmania is an independent subproblem

Page 14: תכנון ובעיות "קשות"

• Discrete variables– finite domains:

• n variables, domain size d implies O(dn) complete assignments• e.g., Boolean CSPs, including Boolean satisfiability (NP-complete)

– infinite domains:• integers, strings, etc.• e.g., job scheduling, variables are start/end days for each job• need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3

• Continuous variables– e.g., start/end times for Hubble Space Telescope observations– linear constraints solvable in polynomial time by linear

programming methods

14

Varieties of CSPs

Page 15: תכנון ובעיות "קשות"

• Assignment problems– e.g., who teaches what class?

• Timetabling problems– e.g., which class (or exam) is offered when and where?

• Hardware Configuration• Spreadsheets• Transportation scheduling• Factory scheduling• Floorplanning

Notice that many real-world problems involve real-valued variables•

15

Real-world CSPs

Page 16: תכנון ובעיות "קשות"

Let’s start with the straightforward (dumb) approach, then fix it.States are defined by the values assigned so far.• Initial state: the empty assignment { }• Successor function: assign a value to an unassigned variable that

does not conflict with current assignment• fail if no legal assignments

• Goal test: the current assignment is complete

1. This is the same for all CSPs (good)2. Every solution appears at depth n with n variables

use depth-first search3. Path is irrelevant, so can also use complete-state formulation4. b = (n - l )d at depth l, hence n! · dn leaves (bad)5.

16

Standard search formulation (incremental)

b is branching factor, d is size of domain, n is number of variables

Page 17: תכנון ובעיות "קשות"

• Let’s say we had 4 variables, each of which could take one of 4 integer values

17

What This Naïve Search Would Look Like

????

1??? 2??? 3??? 4???

?1?? ?2?? ?3?? ?4?? ??1? ??2? ??3? ??4? ???1 ???2 ???3 ???4

Etc.…terrible branching factor

11?? 12?? 13?? 14?? 1?1? 1?2? 1?3? 1?4? 1??1 1??2 1??3 1??43

At start, all unassigned

Page 18: תכנון ובעיות "קשות"

18

Backtracking example

Page 19: תכנון ובעיות "קשות"

19

Backtracking example

Page 20: תכנון ובעיות "קשות"

20

Backtracking example

Page 21: תכנון ובעיות "קשות"

21

Backtracking example

Page 22: תכנון ובעיות "קשות"

יש כמה דרכים איך לשפר את התהליך...•איזה ענף בודקים ראשון–איזה בודקים בפעם השנייה, וכו'–האם אפשר לעצור את התהליך באמצע?–האם אפשר לנצל מידע על הבעיה?–האם אפשר לגזום העץ?–

22

שיפורים

Page 23: תכנון ובעיות "קשות"

• Minimum remaining values (MRV):• choose the variable with the fewest legal values

23

Minimum Remaining Values

All are the same

here

Two equivalent ones here

Clear choice

Page 24: תכנון ובעיות "קשות"

• Tie-breaker among MRV variables

• Degree heuristic: choose the variable with the most constraints on remaining variables

24

Degree Heuristic

Page 25: תכנון ובעיות "קשות"

• Given a variable, choose the least constraining value:

• the one that rules out the fewest values in the remaining variables

25

Least Constraining Value

Page 26: תכנון ובעיות "קשות"

• Given a variable, choose the most constraining value:– This is VERY constrained, so let’s do it first…

26

Most Constraining Value

Page 27: תכנון ובעיות "קשות"

• Idea: – Keep track of remaining legal values for unassigned

variables– Terminate search when any variable has no legal values–

27

Forward checking

Page 28: תכנון ובעיות "קשות"

• Tasmania and mainland are independent subproblems

• Subproblems identifiable as connected components of constraint graph

28

Problem Structure

Page 29: תכנון ובעיות "קשות"

• Hill-climbing, simulated annealing typically work with “complete” states, i.e., all variables assigned

• To apply to CSPs:– use complete states, but with unsatisfied constraints– operators reassign variable values

• Variable selection: randomly select any conflicted variable

• Value selection by min-conflicts heuristic:– choose value that violates the fewest constraints– i.e., hill-climb with h(n) = total number of violated

constraints–

29

Iterative Algorithms for CSPs

Page 30: תכנון ובעיות "קשות"

Example: Sudoku

Variables:Each )open( square

Domains:{1,2,…,9}

Constraints:

9-way alldiff for each row

9-way alldiff for each column

9-way alldiff for each region

Page 31: תכנון ובעיות "קשות"

Very Important CSPs: Scheduling

• Many industries. Many multi-million $ decisions. Used extensively for space mission planning. Military uses.

• People really care about improving scheduling algorithms! Problems with phenomenally huge state spaces. But for which solutions are needed very quickly

• Many kinds of scheduling problems e.g.:– Job shop: Discrete time; weird ordering of operations

possible; set of separate jobs.– Batch shop: Discrete or continuous time; restricted

operation of ordering; grouping is important.

Page 32: תכנון ובעיות "קשות"

Scheduling• A set of N jobs, J1,…, Jn.

• Each job j is composed of a sequence of operations Oj

1,..., OjLj

• Each operation may use resource R, and has a specific duration in time.

• A resource must be used by a single operation at a time.

• All jobs must be completed by a due time.• Problem: assign a start time to each job.

Page 33: תכנון ובעיות "קשות"

"יש "מעבר פאזהCheeseman 1993

Page 34: תכנון ובעיות "קשות"

• CSPs are a special kind of search problem:– states defined by values of a fixed set of variables– goal test defined by constraints on variable values

• Backtracking = depth-first search with one variable assigned per node

• Variable ordering (MRV, degree heuristic) and value selection (least constraining value) heuristics help significantly

• Forward checking prevents assignments that guarantee later failure

• Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies

• The CSP representation allows analysis of problem structure• Tree-structured CSPs can be solved in linear time• Iterative min-conflicts is usually effective in practice

34

Summary