Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from sklearn.neighbors import NearestNeighbors
random_seed = 123
random = np.random.RandomState(random_seed)
"""
* Randomly place agents in a two dimensional world. Place the agents at uniformly random x locations in the range $[-M,M]$ and similary for random y locations.
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from sklearn.neighbors import NearestNeighbors
random_seed = 123
random = np.random.RandomState(random_seed)
"""
* Randomly place agents in a two dimensional world. Place the agents at uniformly random x locations in the range $[-M,M]$ and similary for random y locations.
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
random_seed = 1234
random = np.random.RandomState(random_seed)
def create_two_graph():
# Lapacian and degree matrix are size of num_agent x num_agent
@aadeshnpn
aadeshnpn / MergeSort.py
Created May 27, 2013 15:21
Advance Sorting Algorithms in Python (Merge Sort, Quick Sort, Radix Sort)
"""@Author:Aadesh Neupane
about.me/neupaneaadesh
aadeshnpnp.com.np
"""
import sys
def merge_sort(a):
length_a = len(a)
if length_a <= 1: return a
m = length_a//2
a_left = a[0:m]
@aadeshnpn
aadeshnpn / BubbleSory.py
Created May 27, 2013 15:16
Sorting Algorithms in Python (Bubble Sort, Insertion Sort, Selection Sort, Linear Search, Binary Search)
#!/usr/bin/env python
"""@Author:Aadesh Neupane
about.me/neupaneaadesh
aadeshnpnp.com.np
"""
import sys
"""Program to sort numbers Using Bubble Sort"""
def bubbleSort(seq):
n=len(seq)
#i=0;j=0
@aadeshnpn
aadeshnpn / Factory.py
Created May 26, 2013 13:58
Factory Method Design Pattern
#!/usr/bin/env python
"""This program demonstrated the Factory Method Pattern
@author :Aadesh Neupane
"""
class Pizza(object):
"""This is the abstract class for Pizza"""
def getPrice(self):
raise NotImplementedError("Should Have implemented Thisn")
class HamPizza(Pizza):
@aadeshnpn
aadeshnpn / AbstractFactory.py
Created May 21, 2013 14:22
Example of Abstract Factory Design Pattern in Python
#!/usr/bin/env python
"""@author : Aadesh Neupane
@Description : demonstrates Abstract Factory Method """
ROBUST = 0
class Shape(): #This class is the main factory class
total=0
def __init__(self): #Constructor
self.total=self.total+1
def draw(self): #Abstract Function
raise NotImplementedError('Should Have implemented This')