Giter Club home page Giter Club logo

Comments (7)

manuparra avatar manuparra commented on August 10, 2024 4

Hello @mhucka, you can use decode(value) and encode(value) to decode Binary representation [True, False, ....] to Integer; both are included in the class Type of platypus

This is a small example:

first_variable = algorithm.result[0].variables[0]
problem.types[0].decode(first_variable)

If your integer type is: Integer(-1,1), it will be encoded to 2 bits [X,Y], for instance -1, will be encoded : [False, False] , 0 [False True], 1 [True, False]. This is the explanation.

from platypus.

dhadka avatar dhadka commented on August 10, 2024 1

structureoptimiser.types[0].decode(first_variable) doesn't work because structureoptimizer is the class itself and not an instance of the class.

Try algorithm.problem.types[0].decode(first_variable).

from platypus.

mhucka avatar mhucka commented on August 10, 2024

Thanks, that helped! I got it to work now.

Is this approach (using decode) the way it must be done? IMHO it would be more convenient and easier to use if the objects in the result field had Python __repr__ or __str__ functions that did the right thing for printing Integer values. Perhaps this is something the developers could investigate for a future release?

from platypus.

PastelBelem8 avatar PastelBelem8 commented on August 10, 2024

I agree with mhucka. Also because it is not consistent with the representation that we are given when addressing Continuous problems.

from platypus.

s-m-amin-ghasemi avatar s-m-amin-ghasemi commented on August 10, 2024

@manuparra
@mhucka

(all thing is in jupyter)
Thank you for suggestion but when I have used

first_variable = algorithm.result[0].variables[0]
Problem.types[0].decode(first_variable)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-145-282c3f73daa6> in <module>
      1 first_variable = algorithm.result[0].variables[0]
----> 2 Problem.types[0].decode(first_variable)

AttributeError: type object 'Problem' has no attribute 'types'


And I think it is because of using :


class structureoptimiser(Problem):
    def __init__(self):
            super(structureoptimiser, self).__init__(…...

Then I have changed it to :

first_variable = algorithm.result[0].variables[0]
structureoptimiser.types[0].decode(first_variable)

but I have gotten:

----------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-138-4dc9e9933591> in <module>
      1 first_variable = algorithm.result[0].variables[0]
----> 2 structureoptimiser.types[0].decode(first_variable)

AttributeError: type object 'structureoptimiser' has no attribute 'types'


note :
structureoptimiser.__mro__

(__main__.structureoptimiser, platypus.core.Problem, object)

from platypus.

s-m-amin-ghasemi avatar s-m-amin-ghasemi commented on August 10, 2024

structureoptimiser.types[0].decode(first_variable) doesn't work because structureoptimizer is the class itself and not an instance of the class.
Try algorithm.problem.types[0].decode(first_variable).

Thank you very much, you are right. it's worked.(Really thank you for time you spent and time you saved for me)

from platypus.

github-actions avatar github-actions commented on August 10, 2024

This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.

from platypus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.