Custom Generator and Evaluator with NSGA2 with binary solutions

91 views
Skip to first unread message

marjorie...@uconn.edu

unread,
Oct 17, 2016, 6:59:47 PM10/17/16
to Inspyred
Hello,

I am interested in using NSGA2 to explore land use planning solutions given multiple objectives. I have tried to create a unique generator so that each solution represents a binary decision (0=don't buy, 1=buy) about 100 parcels. Therefore, a solution should be a string of one hundred 0's and 1's.

I also created a custom evaluator that generates fitness values based on which parcels are bought (i.e., the 1's). My fitness values are total area, total cost, and number of priority habitats included.

I have been finding this previous discussion thread particularly helpful, but I don't need the multiprocessing component: https://groups.google.com/forum/#!topic/inspyred/oH2UmnI0n5A

My current issue is that the 'Best Solutions' output is only giving one solution, rather than a bunch of them like the demo NSGA2 code does (http://aarongarrett.github.io/inspyred/examples.html#nondominated-sorting-genetic-algorithm-nsga-ii).

I've attached a working, but incorrect code. I've hard coded the spatial analysis part of the data to avoid compatibility issues. My code is usually designed to interface with the arcpy module which requires a licensed with ESRI's ArcGIS software.

My guess is the issue is in one of my custom functions, but I have exhausted my novice Python know-how at this point. Any insight would be greatly appreciated!

Sincerely,

Mauri Liberati


inspyred_NSGAII_discussionboard.py

James Arruda

unread,
Oct 17, 2016, 7:22:27 PM10/17/16
to insp...@googlegroups.com
Your line 79 just needs to be tabbed back one level. You're only returning the first fitness right now.

Also, you have a '<>', which fails on my machine (python 3.5). Use '`!=' instead if it breaks for you.

Finally, your fitness is set to maximize all outputs (including cost), which will tend to give you a small number of solutions (if all outputs are correlated somewhat). This section in the docs: http://aarongarrett.github.io/inspyred/reference.html?highlight=maximize#inspyred.ec.emo.Pareto explains how to use the maximize properly. In your case, line 77 needs to have an input to the Pareto object creation method. Something like `maximize = [1, 1, 0]` will try to have the most area and tier1s with a low cost.

Doing those case a large set of final results when I ran it.

James



--
You received this message because you are subscribed to the Google Groups "Inspyred" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inspyred+unsubscribe@googlegroups.com.
To post to this group, send email to insp...@googlegroups.com.
Visit this group at https://groups.google.com/group/inspyred.
For more options, visit https://groups.google.com/d/optout.

marjorie...@uconn.edu

unread,
Apr 5, 2017, 9:00:52 AM4/5/17
to Inspyred
In looking for more info on this forum, I realized I never said thanks for the previous help!!! And now I'm asking for more...

I was wondering if there is a way to link the fitness outputs to the solutions that generated them? For my code, the fitness is based on three objectives, but those objectives are determined by a longer binary string. I can output the fitnesses of the best solutions, but I'm not sure how to access the binary strings that they are based off. 

Thanks for your help!
To unsubscribe from this group and stop receiving emails from it, send an email to inspyred+u...@googlegroups.com.

Aaron Garrett

unread,
Apr 5, 2017, 10:14:48 AM4/5/17
to Inspyred
I'm not sure I understand. At the end, you should have a population of individuals (or an archive). You are able to ask each individual for its fitness, yes? If so, then you just need to ask the individual for its candidate.

for individual in final_population:
    print(individual.candidate)
    print(individual.fitness)
--
Aaron Garrett, Ph.D.
Associate Professor
Computer Science
131 Ayers Hall
Jacksonville State University
Jacksonville, AL  36265

marjorie...@uconn.edu

unread,
Apr 5, 2017, 10:19:05 AM4/5/17
to Inspyred
I think the problem is I don't know how to create or populate the 'final_population' object you refer to.

-Mauri

Aaron Garrett

unread,
Apr 5, 2017, 10:32:15 AM4/5/17
to Inspyred
In the code you attached previously, there were two variables, final_pop and final_arc. Looping through either of those can be done like in my example. They both contain individuals that have fitness and candidate attributes.

More generally, the evolve method returns the population of individuals from the final generation. After the evolve method completes, you can also ask the EC for the archive (which may or may not have been used, depending on your strategy).

marjorie...@uconn.edu

unread,
Apr 5, 2017, 10:41:34 AM4/5/17
to Inspyred
Okay that is very helpful - I was getting the final_pop and the archive confused. 

I also realize that there may be an issue earlier in my code. I would expect the print(individual.candidate) to return the binary string but it is producing numbers with decimals instead. 

-Mauri

Aaron Garrett

unread,
Apr 5, 2017, 10:44:20 AM4/5/17
to Inspyred
Can you show me your code? That would make it easier for me to help.

marjorie...@uconn.edu

unread,
Apr 5, 2017, 10:55:05 AM4/5/17
to Inspyred
Absolutely, see attached.

-Mauri
inspyred_NSGAII_discussionboard_2017.04.05.py

Aaron Garrett

unread,
Apr 5, 2017, 12:06:17 PM4/5/17
to Inspyred
OK. So you were using non-binary variators, and that was what was causing the real-valued candidates. You don't have to use the variators I put in this file, but you need to make sure that the ones you use preserve the binary nature of your candidates. I changed a few other things in your code because you were not really using Python correctly. The updated version is attached.
forest_optimization.py

marjorie...@uconn.edu

unread,
Apr 5, 2017, 12:48:33 PM4/5/17
to Inspyred
Thank you so much for your help! Works like a charm now.

-Mauri

gaope...@126.com

unread,
Aug 18, 2019, 10:24:27 AM8/18/19
to Inspyred
May I know what the input data mean in your code?

For example, the meaning of "[237569.14, u'RO30', 2206200.0, 19740, 0, 10880]".



在 2017年4月6日星期四 UTC+8上午12:06:17,Aaron Garrett写道:
To unsubscribe from this group and stop receiving emails from it, send an email to insp...@googlegroups.com.

To post to this group, send email to insp...@googlegroups.com.
Visit this group at https://groups.google.com/group/inspyred.
For more options, visit https://groups.google.com/d/optout.

mlibe...@gmail.com

unread,
Aug 18, 2019, 10:43:13 AM8/18/19
to Inspyred
The input data are property attributes for my study area - e.g., total area, total cost, amount of area for a priority habitat type, zoning type. 

If it's helpful, I posted the final script for the associated publication on GitHub: https://github.com/MLiberati/RefugeTradeoffs

-Mauri
Reply all
Reply to author
Forward
0 new messages