1

i have a question:

I try to programing an ANT algorithm on python but I have a code on C++, and i don't know how to programing this part:

typedef struct {
    int x;
    int y;
} cityType;

typedef struct {
    int curCity;
    int nextCity;
                       //MAX_CITIES
    unsigned char tabu[15];
    int pathIndex;
                       //MAX_CITIES
    unsigned char path[15];
    double tourLength;
} antType;

I programing this, but i am not realy sure

class CityType:
    def __init__(self):
        self.x = arange(MAX_CITIES)
        self.y = arange(MAX_CITIES)

# Class AntType
class AntType:
    def __init__(self):
        self.curCity = arange(MAX_ANTS)
        self.nextCity = arange(MAX_ANTS)
        self.tabu = arange(MAX_ANTS)
        self.pathIndex = arange(MAX_ANTS)
        self.path = arange(MAX_ANTS)
        self.tourLength = arange(MAX_ANTS)

Thanks

3
  • am I supposed to know what an ANT algorithm is? What is an ANT algorithm? Commented Jul 21, 2012 at 23:49
  • @tiwo: Relax, it's not really relevant to the question. Commented Jul 21, 2012 at 23:54
  • docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html Implied from foo import arange statements not shown on SO make things challenging. Commented Jul 22, 2012 at 0:12

1 Answer 1

2

There is nothing really wrong with that. But in trying to do a word-by-word translation, you are not using the full power and conveniance that Python offers.

For example, if CityType has only two members, x and y, maybe just a tuple of length two is more pythonic. The NamedTuple provides access to tuple members "by name".

Sign up to request clarification or add additional context in comments.

1 Comment

Hi tiwo, thanks for your answer in this moment i am changing my code, if its ok i will tell you about it. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.