models created
commit
8cc4dbd478
|
|
@ -0,0 +1 @@
|
||||||
|
env/
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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')
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import unittest
|
||||||
|
import cyclic_contracts
|
||||||
|
|
||||||
|
|
||||||
|
class CyclicTest(unittest.TestCase):
|
||||||
|
"""docstring for CyclicTest."""
|
||||||
|
|
||||||
|
def test_loads():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
Loading…
Reference in New Issue