commit 8cc4dbd4787d405f489d5a69f23eeecd9389c6e8 Author: Malar Kannan Date: Fri Jun 30 09:12:34 2017 +0530 models created diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdaab25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +env/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..6616aa4 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +Problem statement: +Suppose a transporter is having 'n' contract; each contract having 'm' routes in which transporter had to +provide vehicles. + +The problem is to identify the cyclicity in contracts, for eg., if contract-1 is for route city1-city2 then +find a return contract from city2-city1; it's possible that vehicle might ply from city2-city3 then look +for a contract for city3-city1. + +Eventually, it should lead to no. of vehicles coming into the city with load = no. of vehicles going out +of the city with load, and all vehicles completing cycle (reaching its original source city). + +From the list of given contracts, cyclicity may not be possible. The number of contracts going into the +city may not equal the number of contracts coming out of the city. The problem output should identify +contract/corridors for which return contract is required and the number of contracts required. + +Note: +Cyclicity chain should not be more than 3 or 4 cities at max. +Loads provided by different contract at different city should be taken as a variable as it would be +different for different city & contract. diff --git a/contracts.txt b/contracts.txt new file mode 100644 index 0000000..077c8b4 --- /dev/null +++ b/contracts.txt @@ -0,0 +1,8 @@ +1 Chennai Bangalore 100 +1 Bangalore Chennai 100 +2 Bangalore Kolkata 200 +2 Bangalore Mumbai 300 +2 Bangalore Cochin 400 +3 Cochin Mumbai 200 +3 Mumbai Chennai 300 +3 Chennai Cochin 500 diff --git a/cyclic_contracts.py b/cyclic_contracts.py new file mode 100644 index 0000000..d2b9f31 --- /dev/null +++ b/cyclic_contracts.py @@ -0,0 +1,49 @@ +class Route(object): + """docstring for Route.""" + def __init__(self, route_id, load,src,dst): + super(Route, self).__init__() + self.route_id = route_id + self.load = load + self.src = src + self.dst = dst + + def __repr__(self): + return str(self.route_id)+":"+self.src+" - "+self.dst+" "+self.load + + +class Contract(object): + """docstring for Contract.""" + def __init__(self, contract_id, routes): + super(Contract, self).__init__() + self.contract_id = contract_id + self.routes = routes + + def __repr__(self): + return "\tContract : "+str(self.contract_id)+"\n\tRoutes\n\t\t"+"\n\t\t".join(map(repr,self.routes)) + +class Transporter(object): + """docstring for Transporter.""" + def __init__(self, contracts): + super(Transporter, self).__init__() + self.contracts = contracts + + @staticmethod + def read_contracts(c_file): + c_lines = open(c_file,'r').readlines() + c_dict = {} + for l in c_lines: + (c_id,src,dst,load) = l.split(' ') + if c_dict.has_key(c_id): + route_id = len(c_dict[c_id]) + c_dict[c_id].append(Route(route_id,load,src,dst)) + else: + c_dict[c_id] = [Route(0,load,src,dst)] + + contrants = [] + for c_id in c_dict: + contrants.append(Contract(int(c_id),c_dict[c_id])) + + return contrants + + +print Transporter.read_contracts('./contracts.txt') diff --git a/cyclic_contracts_test.py b/cyclic_contracts_test.py new file mode 100644 index 0000000..0d26d19 --- /dev/null +++ b/cyclic_contracts_test.py @@ -0,0 +1,14 @@ +import unittest +import cyclic_contracts + + +class CyclicTest(unittest.TestCase): + """docstring for CyclicTest.""" + + def test_loads(): + + + + +if __name__ == '__main__': + unittest.main()