TheR3dWizard / youSupply_Hackfest

1 stars 3 forks source link

New functions / classes for path calculation #36

Open akashShanmugraj opened 1 month ago

akashShanmugraj commented 1 month ago

I cant describe what I need exactly but anyways I'll try

You can make modifications in the simulation.py file and have algorithmLogic.py for reference

TheR3dWizard commented 1 month ago

in case of these test cases except the last one, the elements of the cluster must be added to the free pool, and for the last test case, the program works

akashShanmugraj commented 1 month ago

How to implement it, what functions do I call to get the paths?

TheR3dWizard commented 1 month ago

theres a getpath() function in Cluster class that will create the path and subpaths and put it as a class variable

akashShanmugraj commented 1 month ago

So after I insert a node inside one cluster, its fine to call the getpath() function for that class and update paths somewhere common like a database?

For example, will this work?

def addrequest():
    body = request.get_json()

    newnode = Node(
        x_pos=body["xposition"],
        y_pos=body["yposition"],
        item=body["itemid"],
        quantity=body["quantity"],
    )
    updatedcluster = centralsystemobject.addrequest(newnode)
    updatedcluster.getpaths()
    return updatedcluster.subpaths
akashShanmugraj commented 1 month ago

@TheR3dWizard I saw this function in the Algorithm Class

    def setSystem(self, system: System) -> None:
        if not self.system.isfeasiblesystem():
            raise ValueError("System does not contain sinks or sources and is not feasible")
        self.system.spectralclustering(num_points=100)
        #figure out what to do with the freepool system
        #possible solutions:
        #1) maybe create a new system 
        #2) change it from a system into just a list of nodes
        #3) change addNode to add a node to the freepool system and not the main system
        self.freepoolsystem = self.system.createfreepool()
        for cluster in self.system.clusterlist:
            cluster.getpath()
            self.paths.append(cluster.path)

according to this function, we are not doing anything with the free pool now?

and also we will replace self.system.spectralclustering(num_points=100) part right? because I cant get how we assumed that number of points is 100 right away

akashShanmugraj commented 1 month ago

In the remove path function from System class

    def removePath(self, path: Path):
        for cluster in self.clusterlist:
            if path in cluster.subpaths:
                cluster.removepath(path)
        for node in path.path:
            self.removeNode(node)

shouldnt we also remove it from their respective clusters?

akashShanmugraj commented 1 month ago

@TheR3dWizard

I tried this implementation

alg = Algorithm()
# uncomment the following lines to test the code
nodelist = [
    Node(x_pos=1, y_pos=1, item="Flashlight", quantity=1), 
    Node(x_pos=2, y_pos=2, item="Flashlight", quantity=-1), 
    Node(x_pos=3, y_pos=3, item="Canned Food", quantity=-1),
    Node(x_pos=3, y_pos=0, item="Canned Food", quantity=1)
]

for node in nodelist:
    alg.addNode(node)
paths = alg.getPaths()

and I got this

Traceback (most recent call last):
  File "/Users/akashshanmugaraj/Documents/hackfestmain/AlgorithmLogic/algorithmlogic.py", line 613, in <module>
    alg.addNode(node)
  File "/Users/akashshanmugaraj/Documents/hackfestmain/AlgorithmLogic/algorithmlogic.py", line 589, in addNode
    self.setSystem(self.system)
  File "/Users/akashshanmugaraj/Documents/hackfestmain/AlgorithmLogic/algorithmlogic.py", line 573, in setSystem
    raise ValueError("System does not contain sinks or sources and is not feasible")
ValueError: System does not contain sinks or sources and is not feasible
akashShanmugraj commented 1 month ago

Dude @TheR3dWizard

This does not work for the system having one node testcase

I cannot add elements onto this

Code

nodelist = [
    Node(x_pos=1, y_pos=1, item="Flashlight", quantity=1), 
]

alg = PathComputationObject()
samplesystem = System(distancelimit=5)

for node in nodelist:
    print(f"Trying to add node {node.x_pos}, {node.y_pos} to the node system")
    samplesystem.addrequest(node)

print(f'Sample System is now all done and set with {samplesystem.numberofnodes} nodes')
alg.setSystem(samplesystem)
paths = alg.getPaths()

newsystem = alg.system
for path in paths:
    print(path)
    path.plotpath()

Output

Trying to add node 1, 1 to the node system
Sample System is now all done and set with 1 nodes
Traceback (most recent call last):
  File "/Users/akashshanmugaraj/Documents/hackfestmain/AlgorithmLogic/migration.py", line 650, in <module>
    alg.setSystem(samplesystem)
  File "/Users/akashshanmugaraj/Documents/hackfestmain/AlgorithmLogic/migration.py", line 597, in setSystem
    raise ValueError("System does not contain sinks or sources and is not feasible")
ValueError: System does not contain sinks or sources and is not feasible
akashShanmugraj commented 1 month ago

I thought you tested all the edge cases already