feat: readme
This commit is contained in:
		
							parent
							
								
									ac91c6403f
								
							
						
					
					
						commit
						2bffb065aa
					
				|  | @ -1,5 +1,4 @@ | ||||||
| #const n = 20. | #const n = 500. | ||||||
| #const k = 5. |  | ||||||
| 
 | 
 | ||||||
| % n-Queens encoding | % n-Queens encoding | ||||||
| 
 | 
 | ||||||
							
								
								
									
										16
									
								
								Assignment1/B/reach.lp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								Assignment1/B/reach.lp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | ||||||
|  | #include "reachin1000". | ||||||
|  | 
 | ||||||
|  | source(3). | ||||||
|  | 
 | ||||||
|  | % Way 1 | ||||||
|  | reach(X) :- source(X). | ||||||
|  | reach(Y) :- edge(X,Y), reach(X). | ||||||
|  | % Way 2 | ||||||
|  | %reach(Y) :- edge(X,Y), reach(X). | ||||||
|  | %reach(X) :- source(X). | ||||||
|  | % Way 3 | ||||||
|  | %reach(X) :- source(X). | ||||||
|  | %reach(Y) :- reach(X), edge(X,Y). | ||||||
|  | % Way 4 | ||||||
|  | %reach(Y) :- reach(X), edge(X,Y). | ||||||
|  | %reach(X) :- source(X). | ||||||
							
								
								
									
										83
									
								
								Assignment1/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								Assignment1/README.md
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,83 @@ | ||||||
|  | # Assignment 1   | ||||||
|  | 
 | ||||||
|  | ## Part A   | ||||||
|  | 
 | ||||||
|  | ### Append   | ||||||
|  | ```shell | ||||||
|  | xsb | ||||||
|  | ```   | ||||||
|  | ```prolog | ||||||
|  | ['A/append.P']. | ||||||
|  | suffix([1,2], [1,2,3,4]). | ||||||
|  | cut([1,2,3]). | ||||||
|  | ```   | ||||||
|  | ### Reach   | ||||||
|  | generate input set   | ||||||
|  | ```shell | ||||||
|  | python randomgen.py [number of nodes] | ||||||
|  | ```   | ||||||
|  | ### Transitive closure and cycle   | ||||||
|  | ```shell | ||||||
|  | xsb | ||||||
|  | ```   | ||||||
|  | ```prolog | ||||||
|  | ['A/cycle.P']. | ||||||
|  | path(1,2) . | ||||||
|  | cycle(1). | ||||||
|  | ```   | ||||||
|  | ### N-queens   | ||||||
|  | ```shell | ||||||
|  | xsb | ||||||
|  | ```   | ||||||
|  | ```prolog | ||||||
|  | ['A/queens.P']. | ||||||
|  | timeNQueen(8). | ||||||
|  | timeOneQueen(8). | ||||||
|  | ```   | ||||||
|  | 
 | ||||||
|  | ## Part B | ||||||
|  | ### Reach   | ||||||
|  | generate input set   | ||||||
|  | ```shell | ||||||
|  | python randomgen.py [number of nodes] | ||||||
|  | ```   | ||||||
|  | ```shell | ||||||
|  | clingo --models 0 B/reach.lp | ||||||
|  | ``` | ||||||
|  | | Input size | Way 1   | Way 2  | Way 3  | Way 4  | | ||||||
|  | | ---------- | ------- | ------ | ------ | ------ | | ||||||
|  | | 10000      | 0.655s  | 0.703s | 0.664s | 0.665s | | ||||||
|  | | 20000      | 1.376s  | 1.446s | 1.290s | 1.292s | | ||||||
|  | | 50000      | 3.355s  | 3.501s | 2.750s | 1.645s | | ||||||
|  | | 100000     | 6.778s  | 5.002s | 3.375s | 3.438s | | ||||||
|  | | 200000     | 12.119s | 7.514s | 7.267s | 7.021s |   | ||||||
|  | 
 | ||||||
|  | Though it looks like the Way4 is way better tha Way 1(Almost twice as fast), but if we let the computer to rest for a while and rerun them the other way(start from 4, then 3, follow by 2 and 1), we got   | ||||||
|  | | Input size | Way 1  | Way 2  | Way 3  | Way 4   | | ||||||
|  | | ---------- | ------ | ------ | ------ | ------- | | ||||||
|  | | 200000     | 7.146s | 7.610s | 7.120s | 12.103s |   | ||||||
|  | 
 | ||||||
|  | It is exactly the other way around! I belive it is because the input file becomes too large | ||||||
|  | (42 MByte), so it waste a lot of time to load it to memory then cache, and the following ones has much higher cache hits rate, so the first one takes way longer than the others. | ||||||
|  | ### N-queens | ||||||
|  | ```shell | ||||||
|  | clingo --models 0 B/nqueens.lp | ||||||
|  | ```   | ||||||
|  | ```shell | ||||||
|  | clingo --models 1 B/nqueens.lp | ||||||
|  | ```   | ||||||
|  | | Number of queens | Time for 1 queen | Time for all queens | | ||||||
|  | | ---------------- | ---------------- | ------------------- | | ||||||
|  | | 8                | 0.004s           | 0.006s              | | ||||||
|  | | 10               | 0.003s           | 0.086s              | | ||||||
|  | | 12               | 0.004s           | 4.909s              | | ||||||
|  | | 14               | 0.006s           | Too long to run     | | ||||||
|  | | 20               | 0.011s           |                     | | ||||||
|  | | 50               | 0.073s           |                     | | ||||||
|  | | 100              | 0.463s           |                     | | ||||||
|  | | 200              | 3.233s           |                     | | ||||||
|  | | 500              | 35.073s          |                     |   | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ## Part C   | ||||||
|  | ### N-queens | ||||||
							
								
								
									
										10
									
								
								Assignment1/randomgen.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Assignment1/randomgen.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,10 @@ | ||||||
|  | import random | ||||||
|  | import sys | ||||||
|  | if len(sys.argv) == 2: x = int(sys.argv[1]) | ||||||
|  | else: x = 1000 | ||||||
|  | file = open("reachin1000", "w")  | ||||||
|  | for i in range(10 * x): | ||||||
|  |     j = random.randint(1,x) | ||||||
|  |     k = random.randint(1,x) | ||||||
|  |     file.write("edge({}, {}).\n".format(i, j)) | ||||||
|  | file.close() | ||||||
							
								
								
									
										2000000
									
								
								Assignment1/reachin1000
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2000000
									
								
								Assignment1/reachin1000
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -1,5 +0,0 @@ | ||||||
| #include "reachin1000". |  | ||||||
| 
 |  | ||||||
| source(3). |  | ||||||
| reach(Y) :- edge(X,Y), reach(X). |  | ||||||
| reach(X) :- source(X). |  | ||||||
|  | @ -1,6 +0,0 @@ | ||||||
| import random |  | ||||||
| x = int(input()) |  | ||||||
| for i in range(10 * x): |  | ||||||
|     j = random.randint(1,x) |  | ||||||
|     k = random.randint(1,x) |  | ||||||
|     print("edge(", j, ",", k, ").") |  | ||||||
							
								
								
									
										400000
									
								
								reachin1000
									
									
									
									
									
								
							
							
						
						
									
										400000
									
								
								reachin1000
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
		Reference in New Issue
	
	Block a user