Skip to content

Commit

Permalink
page updates, added spaces around table syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
adimail committed May 22, 2024
1 parent a35f5ff commit cc22449
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/AI/8-puzzle.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent: AI

# 8-Puzzle Problem

The 8-puzzle is a sliding puzzle consisting of eight tiles, numbered 1 through 8, placed in a 3x3 grid with one empty space. The goal is to rearrange the tiles from a given initial configuration to a goal configuration by sliding tiles into the empty space.
> The 8-puzzle is a sliding puzzle consisting of eight tiles, numbered 1 through 8, placed in a 3x3 grid with one empty space. The goal is to rearrange the tiles from a given initial configuration to a goal configuration by sliding tiles into the empty space.
![puzzle](https://www.aiai.ed.ac.uk/~gwickler/images/8-puzzle-states.png)

Expand Down Expand Up @@ -159,7 +159,7 @@ for soln in solution:


---
## Here is the entire code for you to copy paste
## Here is the entire code for you to try

```python
class PuzzleState:
Expand Down
8 changes: 6 additions & 2 deletions docs/AI/flight-schedulling-greedy-search.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
layout: default
title: Flight Scheduling with Greedy Algorithms
title: Flight Scheduling
parent: AI
---

# Flight Scheduling with Greedy Algorithms

This code performs the following steps:

- Define a Flight class to hold flight details.
Expand Down Expand Up @@ -124,7 +126,7 @@ print(overlapedflights_df)


---
## Here is the entire code for you to copy paste
## Here is the entire code for you to try

```python
import pandas as pd
Expand Down Expand Up @@ -185,13 +187,15 @@ print(overlapedflights_df)
Output:

Scheduled flights:

| Flight Number | Departure Time | Arrival Time | Maintenance Time |
|---------------|----------------|--------------|------------------|
| flight1 | 08:00 | 10:30 | 30 |
| flight3 | 14:00 | 16:30 | 20 |
| flight5 | 20:00 | 22:30 | 25 |

Delayed Flights due to overlap

| Flight Number | Departure Time | Arrival Time | Maintenance Time |
|---------------|----------------|--------------|------------------|
| flight2 | 11:00 | 13:30 | 45 |
Expand Down
4 changes: 2 additions & 2 deletions docs/AI/n-queen.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent: AI

# N-Queens Problem

Our goal is to develop a solution to place N chess queens on an N×N chessboard so that no two queens threaten each other.
> Our goal is to develop a solution to place N chess queens on an N×N chessboard so that no two queens threaten each other.
![problem](https://miro.medium.com/v2/resize:fit:457/0*ScgscJU4q5zWf6lk.png)

Expand All @@ -33,7 +33,7 @@ graph TD;
```

---
## Here is the entire code for you to copy paste
## Here is the entire code for you to try

```python
def IsSafe(board, row, col):
Expand Down
46 changes: 37 additions & 9 deletions docs/AI/tsp.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parent: AI

# Travelling Salesman Problem in python

Given a list of cities and the distances between them, the objective is to find the optimal tour that visits each city exactly once and returns to the starting city, minimizing the total distance traveled.
> Given a list of cities and the distances between them, the objective is to find the optimal tour that visits each city exactly once and returns to the starting city, minimizing the total distance traveled.
## Algorithm

Expand All @@ -25,22 +25,26 @@ graph TD;
```

---
## Here is the entire code for you to copy paste
## Here is the entire code for you to try

```python
import math
import pandas as pd

def TSP(cities):
currentCity = cities[0]
tour = [currentCity]
SetVisited(currentCity)
totalDistance = 0
while Check(cities):
nearest_city = FindNearestCity(currentCity, cities)
nearest_city, distance = FindNearestCity(currentCity, cities)
tour.append(nearest_city)
SetVisited(nearest_city)
currentCity = nearest_city
totalDistance = totalDistance + distance

tour.append(tour[0])
return tour
return tour, totalDistance

def Check(cities):
return any(city['visited'] == False for city in cities)
Expand All @@ -54,7 +58,7 @@ def FindNearestCity(currentCity, cities):
if distance < nearest_distance:
nearest_distance = distance
nearest_city = city
return nearest_city
return nearest_city, distance

def SetVisited(city):
city['visited'] = True
Expand All @@ -70,13 +74,37 @@ cities = [
{'name': 'PCMC', 'x': 0, 'y': 2, 'visited': False}
]

print("Cities")
for city in cities:
print(f"{city['name']} - ({city['x']}, {city['y']})")
tour, totalDistance = TSP(cities)

tour = TSP(cities)
df = pd.DataFrame(cities)

print(df)

print("\nTour:")
for i, city in enumerate(tour):
print(f"Step {i+1}: Visit {city['name']}")

print(f'\nTotal trip cost: {totalDistance}')

```

output:

```
name x y visited
Pune 0 0 True
Wakad 1 1 True
Moshi 2 2 True
Hadapsar 1 3 True
PCMC 0 2 True
Tour:
Step 1: Visit Pune
Step 2: Visit Wakad
Step 3: Visit Moshi
Step 4: Visit Hadapsar
Step 5: Visit PCMC
Step 6: Visit Pune
Total trip cost: 6.82842712474619
```

0 comments on commit cc22449

Please sign in to comment.