In an object-oriented language, an instance of a class is an element of computation (1 is an instance of the class Integer, and Integer is a subclass of Number). In a type-guided language, a realization of a type is an element of computation (1 is a realization of type Int, and type Int is a subtype of Integer and of Number). The work done through the use of classes is taken up through types and methods defined on/over types. There is no "better" general alternative for translating class-based design than applying Julia's types and methods. A better question: "How should I define PhysicalNodes in Julia differently than I did in Python?"
On Saturday, August 27, 2016 at 2:52:24 AM UTC-4, [email protected] wrote: > > What are the alternatives to using classes in Julia apart from types? Can > you please explain how I can define the PhysicalNodes class in Julia the > same way like I did in python? > > On Friday, 26 August 2016 23:16:39 UTC+2, Cedric St-Jean wrote: >> >> It's not possible in Julia at the moment. There's an issue for it. >> <https://github.com/JuliaLang/julia/issues/269> I think the main options >> are: >> >> - Don't declare the types. This may make it slower, but depending on the >> use case it might not be a big deal >> - Use parametric types, i.e. >> >> type Node{T} >> edges::Vector{T} >> end >> >> type Edge{T} >> node::T >> end >> >> >> >> On Friday, August 26, 2016 at 1:38:38 PM UTC-4, [email protected] wrote: >>> >>> Hello all, >>> >>> I'm making a transition from Python to Julia and in the process, I've >>> encountered a small difficulty. While in python, i declared three classes >>> as follows: >>> >>> class PHY_NODES: >>> def __init__(self, nodeID, nodenum, x, y, demands): >>> self.id = nodeID >>> self.nodenum = nodenum >>> self.x = x >>> self.y = y >>> self.inEdges = [] >>> self.outEdges = [] >>> self.demands = demands >>> >>> def __str__(self): >>> return "Physical Node ID: nodenum: %4d x: %.3f y: %.3f" %( >>> self.id, self.nodenum, self.x, self.y ) >>> >>> def addInEdge(self, edge): >>> self.inEdges.append( edge ) >>> >>> def addOutEdge(self, edge): >>> self.outEdges.append( edge ) >>> >>> >>> class PHY_LINKS: >>> def __init__(self, linkID, source, destination, SourceID, >>> DestinationID,): >>> self.linkID = linkID >>> self.source = source >>> self.destination = destination >>> self.SourceID = SourceID >>> self.DestinationID = DestinationID >>> >>> >>> def __str__(self): >>> return "Physical Link ID: %4d source: %s destination: %s >>> SourceID: %4d DestinationID: %4d " %(self.linkID, self.source, >>> self.destination, self.SourceID, self.DestinationID, ) >>> >>> >>> class DEMAND: >>> def __init__(self, PoP_bdw_up, PoP_stor, PoP_pro, MME_bdw_up, >>> MME_stor, MME_pro,demandID): >>> self.PoP_bdw_up = PoP_bdw_up >>> self.PoP_stor = PoP_stor >>> self.PoP_pro = PoP_pro >>> self.MME_bdw_up = MME_bdw_up >>> self.MME_stor = MME_stor >>> self.MME_pro = MME_pro >>> self.demandID = demandID >>> >>> >>> def __str__(self): >>> return " PoPbdwup: %.3f PoPstor: %.3f PoPpro: %.3f MMEbdwup: >>> %.3f MMEstor: %.3f MMEpro: %.3f, self.demandID ) >>> >>> However, I have some trouble when replicating the same in Julia >>> especially due to the nested classes in PHY_NODES (self.inEdges as well as >>> self,demands) >>> >>> The Julia version of the Phy_Node class is as below: >>> >>> type PhysicalNodes >>> ID:Int >>> name:String >>> x: Float >>> y:Float >>> inEdges: ? >>> outEdges: ? >>> demands: ? >>> end >>> >>> I don't how to declare the inEdges, outEdges and demands here. Could you >>> please help me with this? >>> >>>
