Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72517

Having trouble in expressing constraints in Python

Newsgroups comp.lang.python
Date 2014-06-03 06:44 -0700
Message-ID <1919ef6f-6aed-4b03-a9b1-ac9e2a2b31a7@googlegroups.com> (permalink)
Subject Having trouble in expressing constraints in Python
From varun7rs@gmail.com

Show all headers | View raw


I have a problem in writing a constraint in Python. Firstly, I wrote the code in AMPL and it was working and I'm using Python for the reason that it is more suitable to handle large data. I managed to write the code quite fine except for one constraint(Link Mapping Constraint). I've attached pieces of code from both AMPL and Python. First part of it is the Link Capacity Constraint in AMPl followed by Python. Second part of the code is the Link Mapping Constraint and I wish to write it in a similar fashion. But, I'm not able to proceed with it. I really appreciate your help.

subject to Link_Capacity_Constraints { (ns1, ns2) in PHY_LINKS}:
	sum {dns in DEMAND} ((f_eN_SGW[dns, ns1, ns2] * (MME_bdw[dns] + IMS_bdw[dns] + PoP_bdw[dns])) + (f_SGW_PGW[dns, ns1, ns2] * PoP_bdw[dns]) + (f_SGW_IMS[dns, ns1, ns2] * IMS_bdw[dns]) + (f_SGW_MME[dns, ns1, ns2] * MME_bdw[dns]) + (f_PGW_PoP[dns, ns1, ns2] * PoP_bdw[dns])) <= capacity_bdw[ns1, ns2];

        for edge in phy_network.edges:
            varNames = []
            varCoeffs = []
            for demand in demands:
                varNames.append("f_eN_SGW_{}_{}_{}".format(demand.demandID, edge.SourceID, edge.DestinationID))
                varCoeffs.append(demand.MME_bdw + demand.IMS_bdw + demand.PoP_bdw )
                varNames.append("f_SGW_PGW_{}_{}_{}".format(demand.demandID, edge.SourceID, edge.DestinationID))
                varCoeffs.append(demand.PoP_bdw)
                varNames.append("f_SGW_IMS_{}_{}_{}".format(demand.demandID, edge.SourceID, edge.DestinationID))
                varCoeffs.append(demand.IMS_bdw)
                varNames.append("f_SGW_MME_{}_{}_{}".format(demand.demandID, edge.SourceID, edge.DestinationID))
                varCoeffs.append(demand.MME_bdw)
                varNames.append("f_PGW_PoP_{}_{}_{}".format(demand.demandID, edge.SourceID, edge.DestinationID))
                varCoeffs.append(demand.PoP_bdw)        
            solver.add_constraint(varNames, varCoeffs, "L", edge.capacity_bdw, "Link_Capacity_Constraints{}_{}_{}".format(edge.SourceID, edge.DestinationID, demand.demandID))

#Link Mapping Constraint
subject to Link_Mapping_Constraints_1{dns in DEMAND, ns1 in PHY_NODES}: sum {(ns1,w) in PHY_LINKS} (f_eN_SGW[dns, w, ns1] - f_eN_SGW[dns, ns1, w]) = x_eN[dns, ns1] - x_SGW[dns, ns1];





Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Having trouble in expressing constraints in Python varun7rs@gmail.com - 2014-06-03 06:44 -0700
  Re: Having trouble in expressing constraints in Python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-06-03 16:15 +0100
    Re: Having trouble in expressing constraints in Python varun7rs@gmail.com - 2014-06-03 14:31 -0700
  Re: Having trouble in expressing constraints in Python Chris Angelico <rosuav@gmail.com> - 2014-06-04 01:19 +1000
  Re: Having trouble in expressing constraints in Python Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-04 01:18 -0600
  Re: Having trouble in expressing constraints in Python varun7rs@gmail.com - 2014-06-06 03:38 -0700

csiph-web