def test_spt_add_nodes_1_1(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) solver = netx.ShortestPathTree(cnfg) x = 703444 y = 5364720 supply = 0 withCap = False startID = net.AddStartNode('start', x, y, supply, cnfg.Treshold, cmap, withCap) x = 703342 y = 5364710 endID = net.AddEndNode('end', x, y, supply, cnfg.Treshold, cmap, withCap) solver.SetOrigin(startID) dests = netx.Destinations() dests.append(endID) solver.SetDestinations(dests) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_mcf_load_nodes(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) ntblname = cnfg.NodesTableName nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cnfg.NodesGeomColumnName, cmap) withCapacity = True net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) startNodes = net.LoadStartNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) endNodes = net.LoadEndNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) solver = netx.MinCostFlow(cnfg) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_spt_add_nodes_1_all(cnfg, cmap): # netx.LOGGER.Initialize(cnfg) # netx.DBHELPER.Initialize(cnfg) atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) solver = netx.ShortestPathTree(cnfg) x = 703444 y = 5364720 supply = 0 withCap = False startID = net.AddStartNode('start', x, y, supply, cnfg.Treshold, cmap, withCap) solver.SetOrigin(startID) # all -> no setting of dests solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_spt_load_nodes_1_n(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) ntblname = cnfg.NodesTableName nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cnfg.NodesGeomColumnName, cmap) withCapacity = False net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) startNodes = net.LoadStartNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) endNodes = net.LoadEndNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) solver = netx.ShortestPathTree(cnfg) solver.SetOrigin( startNodes[0] [0]) #first start; first item of tuple is the new internal id dests = netx.Destinations() for d in endNodes: dests.append(d[0]) #first item of tuple is the new internal id solver.SetDestinations(dests) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_add_nodes(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) print(("Original Node ID of 1: " + net.GetOriginalNodeID(1))) x = 703444 y = 5364720 supply = 1 withCap = False newNodeID = net.AddStartNode('1', x, y, supply, cnfg.Treshold, cmap, withCap) print(("Original Node ID of {0}: {1}".format( newNodeID, net.GetOriginalNodeID(newNodeID)))) x = 703342 y = 5364710 supply = -1 newNodeID = net.AddStartNode('2', x, y, supply, cnfg.Treshold, cmap, withCap) print(("Original Node ID of {0}: {1}".format( newNodeID, net.GetOriginalNodeID(newNodeID)))) del net
def test_odm_add_nodes(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) solver = netx.OriginDestinationMatrix(cnfg) startIDs = [] x = 703444 y = 5364720 supply = 0 withCap = False startIDs.append( net.AddStartNode('start1', x, y, supply, cnfg.Treshold, cmap, withCap)) x = 703434 y = 5364710 startIDs.append( net.AddStartNode('start2', x, y, supply, cnfg.Treshold, cmap, withCap)) destIDs = [] x = 703342 y = 5364710 destIDs.append( net.AddEndNode('end1', x, y, supply, cnfg.Treshold, cmap, withCap)) x = 703332 y = 5364720 destIDs.append( net.AddEndNode('end2', x, y, supply, cnfg.Treshold, cmap, withCap)) starts = netx.ODNodes() for s in startIDs: starts.append((s, str(s))) solver.SetOrigins(starts) dests = netx.ODNodes() for d in destIDs: dests.append((d, str(d))) solver.SetDestinations(dests) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_mst(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) solver = netx.MinimumSpanningTree(cnfg) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_load_nodes_2(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) ntblname = cnfg.NodesTableName nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cnfg.NodesGeomColumnName, cmap) withCapacity = False net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) startNodes = net.LoadStartNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) endNodes = net.LoadEndNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) del net
def test_mcf(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) startIDs = [] x = 702370 y = 5352540 supply = 10 withCap = True startIDs.append( net.AddStartNode('start1', x, y, supply, cnfg.Treshold, cmap, withCap)) x = 702360 y = 5352530 supply = 5 startIDs.append( net.AddStartNode('start2', x, y, supply, cnfg.Treshold, cmap, withCap)) destIDs = [] x = 699022 y = 5355445 supply = -5 destIDs.append( net.AddEndNode('end1', x, y, supply, cnfg.Treshold, cmap, withCap)) x = 702237 y = 5358572 supply = -15 destIDs.append( net.AddEndNode('end2', x, y, supply, cnfg.Treshold, cmap, withCap)) solver = netx.MinCostFlow(cnfg) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def test_load_nodes(cnfg, cmap): atblname = cnfg.ArcsTableName ntblname = cnfg.NodesTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cnfg.NodesGeomColumnName, cmap) # NewNode to InputNode nodes = netx.InputNodes() for newNode in nodesTable: inputNode = netx.InputNode() inputNode.extNodeID = newNode.extNodeID inputNode.nodeSupply = newNode.supply nodes.append(inputNode) net = netx.Network(arcsTable, nodes, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) del net
def test_odm_load_nodes(cnfg, cmap): atblname = cnfg.ArcsTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) ntblname = cnfg.NodesTableName nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cnfg.NodesGeomColumnName, cmap) withCapacity = False net = netx.Network(arcsTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) startNodes = net.LoadStartNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) endNodes = net.LoadEndNodes(nodesTable, cnfg.Treshold, atblname, cnfg.ArcsGeomColumnName, cmap, withCapacity) solver = netx.OriginDestinationMatrix(cnfg) starts = netx.ODNodes() for s in startNodes: starts.append(s) dests = netx.ODNodes() for d in endNodes: dests.append(d) solver.SetOrigins(starts) solver.SetDestinations(dests) solver.Solve(net) optimum = solver.GetOptimum() del net, solver return optimum
def main(): f = open( r"/home/hahne/dev/netxpert/test/bin/Release/ODMatrixCnfg_Big.json", "r") content = f.read() f.close() config_json = json.loads(content)['c'] #c is root cnfg = netx.Config() cnfg.ArcsGeomColumnName = config_json["ArcsGeomColumnName"].encode( 'ascii', 'ignore') cnfg.ArcsTableName = config_json["ArcsTableName"].encode('ascii', 'ignore') cnfg.NetXDBPath = config_json["NetXDBPath"].encode('ascii', 'ignore') cnfg.TestCase = config_json["TestCase"] cnfg.NodesTableName = config_json["NodesTableName"].encode( 'ascii', 'ignore') cnfg.NodesGeomColumnName = config_json["NodesGeomColumnName"].encode( 'ascii', 'ignore') cnfg.NodeIDColumnName = config_json["NodeIDColumnName"].encode( 'ascii', 'ignore') cnfg.NodeSupplyColumnName = config_json["NodeSupplyColumnName"].encode( 'ascii', 'ignore') cnfg.ArcIDColumnName = config_json["ArcIDColumnName"].encode( 'ascii', 'ignore') cnfg.FromNodeColumnName = config_json["FromNodeColumnName"].encode( 'ascii', 'ignore') cnfg.ToNodeColumnName = config_json["ToNodeColumnName"].encode( 'ascii', 'ignore') cnfg.CostColumnName = config_json["CostColumnName"].encode( 'ascii', 'ignore') cnfg.CapColumnName = config_json["CapColumnName"].encode('ascii', 'ignore') cnfg.OnewayColumnName = config_json["OnewayColumnName"].encode( 'ascii', 'ignore') cnfg.IsDirected = config_json["IsDirected"] cnfg.LogLevel = config_json["LogLevel"] cnfg.LogFileFullPath = config_json["LogFileFullPath"].encode( 'ascii', 'ignore') cnfg.SpatiaLiteHome = config_json["SpatiaLiteHome"].encode( 'ascii', 'ignore') cnfg.SpatiaLiteCoreName = config_json["SpatiaLiteCoreName"].encode( 'ascii', 'ignore') cnfg.CleanNetwork = config_json["CleanNetwork"] cnfg.ResultDBType = config_json["ResultDBType"] cnfg.ResultDBPath = config_json["ResultDBPath"].encode('ascii', 'ignore') cnfg.Treshold = config_json["Treshold"] #print netx.LOGGER.IsInitialized #if not netx.LOGGER.IsInitialized: print "init logger" netx.LOGGER.Initialize(cnfg) cmap = netx.ColumnMap() cmap.arcIDColName = cnfg.ArcIDColumnName cmap.fromColName = cnfg.FromNodeColumnName cmap.toColName = cnfg.ToNodeColumnName cmap.costColName = cnfg.CostColumnName #cmap.capColName = cnfg.CapColumnName #cmap.onewayColName = cnfg.OnewayColumnName cmap.nodeIDColName = cnfg.NodeIDColumnName cmap.supplyColName = cnfg.NodeSupplyColumnName #if not netx.DBHELPER.IsInitialized: print "init dbhelper" netx.DBHELPER.Initialize(cnfg) atblname = cnfg.ArcsTableName ntblname = cnfg.NodesTableName arcsTable = netx.DBHELPER.LoadNetworkFromDB(atblname, cmap) #nodesTable = netx.DBHELPER.LoadNodesFromDB(ntblname, cmap) net = netx.Network(arcsTable, cmap, cnfg) #net = netx.Network(arcsTable, nodesTable, cmap, cnfg) net.ConvertInputNetwork(cnfg.CleanNetwork) print "Original Node ID of 1: " + net.GetOriginalNodeID(1) x = 703444 y = 5364720 supply = 1 withCap = False print net.AddStartNode('1', x, y, supply, cnfg.Treshold, cmap, withCap) x = 703342 y = 5364710 supply = -1 print net.AddEndNode('2', x, y, supply, cnfg.Treshold, cmap, withCap)