# Regenerating a Floor Plan in Python

**URL:** <https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [April 21, 2020, 5:34am UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989 "2020-04-21T05:34:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mits](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mits](https://discourse.processing.org/u/Mits)\
**Post date:** [April 21, 2020, 5:34am UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/1 "2020-04-21T05:34:31Z")

</div>

I have a floor plan. I want to take the image and reproduce the same by exchanging zones and optimize the floor layout. I have to code in Python. I tried using Genetic Algorithm but I didn’t get clarity on how to plot the image on grid and further switch the zones and reproduce the new floor plan. Can anyone help ?

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 21, 2020, 8:18pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/2 "2020-04-21T20:18:05Z")

</div>

Can you show us some code of the genetic algorithm you tried?

This seem like a very hard / complex homework. I won’t write you any code, but I can tell you how I guess I would tackle the issue:

- Encode the Floor Plan as list of numbers (HARD: best if it makes invalid FPs to be rare)
- Write code to draw the FP from the list representation
- Write code to check if a representation is a valid FP (HARD)
- Define exactly what optimization means, what are you measuring on the FP? (HARD)
- Write code that calculates a fitnes value (that is, the measure that will be optimized)
- Write code that generates a population of FPs
- Implement the GA:
  - Measure FP fitnes
  - Recombine ‘best’ FPs
  - Mutate some FPs
  - …rince and repeat

It might be slow in Processing Python mode. Maybe you could do this in Python 3 and use Processing Python mode just to show the results (draw the FPs from the numer list)?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 21, 2020, 9:19pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/3 "2020-04-21T21:19:07Z")

</div>

Yeah, can you show the initial image also?

---

<div class="post-metadata">

**Author:** ![Mits](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mits](https://discourse.processing.org/u/Mits)\
**Post date:** [April 22, 2020, 6:36am UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/4 "2020-04-22T06:36:04Z")

</div>

![1](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e5178795c9c2ae813dc4632383d296a9dcf56dd3.png)

---

<div class="post-metadata">

**Author:** ![Mits](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@Mits](https://discourse.processing.org/u/Mits)\
**Post date:** [April 22, 2020, 6:36am UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/5 "2020-04-22T06:36:49Z")

</div>

I know the process. But I needed help with the code itself.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 22, 2020, 10:30am UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/6 "2020-04-22T10:30:51Z")

</div>

Hello,

thank you!

then you would have to share your code and ask more specific questions, even related to functions or line numbers where you are stuck.

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)\
**Post date:** [April 22, 2020, 3:14pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/7 "2020-04-22T15:14:04Z")

</div>

As @Chrisir said, in order to help we need to see your code.

And I would like to know more about the problem itself:

- I wonder how could we represent a generic Floor Plan in a data structure?
- Are the assigned areas fixed or variable? (can the packing area change in size or only position?)
- What are we optimizing exactly?  
(looks like there is an industrial process going on, is there a proximity matrix you have as a target? is there a product flow?)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 22, 2020, 3:33pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/8 "2020-04-22T15:33:31Z")

</div>

Yeah, very good questions here!

Is the size of the house fixed? So the outer outline always the same?

Are there big machines so that one room has a minimum size (x or y)? So that the machine fits in?

**Data structure**

ONE idea, there are other ways of course!

- Basically you have a class Room with pos (x,y) and size (x,y) and name.

- Then you have a list of the rooms

- Now, when you make the room smaller (x), the room right from it gets bigger (x) automatically.

- Same for y.

- So there is a connection between the rooms. All rooms in one row must be together as wide as the house. All rooms in one column as high.

Also when one room 1 produces product A and product A is needed in room 2, they should be adjacent (are there even conveyor belts?). So this would be a rule set that should be part of the fitness function.

Chrisir

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [April 27, 2020, 4:54pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/9 "2020-04-27T16:54:48Z")

</div>

> [@Mits](#):
>
> I want to take the image

Do you mean that you are scanning an image (like a jpg, or an svg, or…?) as input to your program, and you are trying to detect the geometry from the image?

Or do you have a data file that defines a floor layout, and you are trying to load the data, draw it is a picture, then change the picture that processing.py makes of that layout data by moving the variables around?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 27, 2020, 10:10pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/10 "2020-04-27T22:10:59Z")

</div>

> [@Mits](#):
>
> I know the process. But I needed help with the code itself.

Then show the code also please

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [April 27, 2020, 11:37pm UTC](https://discourse.processing.org/t/regenerating-a-floor-plan-in-python/19989/11 "2020-04-27T23:37:15Z")

</div>

Just my intuition but it feels like the OP has in fact little understanding of what he/she is asking. Googling the picture provided above leads to duplicate questions on SO that have been down-voted probably due to the lack of research/explanations. In one of those (deleted since) OP clearly says that he/she doesn’t know how/where to start.

I hope the OP will make the effort to articulate the problem in a clearer statement because this is an interesting topic that I would happily read or even elaborate on (if I can).

Other questions that would be interesting to ask:

- Is the evolutionary approach mandatory ? Depending on the objective Constraint Programming could be an option too.

- Why [resorting to computer vision](https://stackoverflow.com/questions/60824855/how-to-obtain-and-store-centroid-coordinates-of-rooms-of-a-floor-plan-image) for such a simple layout ? (Why not using rectangles instead ?)
