question

Tuan avatar image
0 Likes"
Tuan asked Jeanette F commented

Flexsim external Genetic Algorithm(GA) via Socket

@Kavika F Hello!!


GA.py

eight-jobs-and-eight-machines.png

The problem to be solved by GA is

Assuming that there are 8 machines and 8 jobs, and each machine can handle any job.

How to allocate jobs to different machines so that the total processing time of the machines is the least.


socket-tcp.py

socket new.fsm


What I want to do is

at the beginning, python randomly generates 3 integers and sends them to Flexsim. After calculation by Flexsim's experimenter, the result is sent back to python. Python evaluates the result through GA. Python then sends another three integers to Flexsim. After being calculated by Flexsim's experimenter, the result will be sent back to python, and python evaluates the result through GA.

Repeat the above process until the result is the least


How do I combine socket-tcp.py with GA.py and modify the code to the way I want?


FlexSim 20.0.10
experimentersocketalgorithm
ga.py (11.6 KiB)
socket-tcp.py (1000 B)
socket-new.fsm (100.3 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Tuan, was Kavika F's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

·
Kavika F avatar image
0 Likes"
Kavika F answered

Hey @Tuan, here's a method you could try. Start by having your socket-tcp.py import your GA.py. Before the while-loop in socket-tcp.py, generate your 3 random numbers and then send them as a delimited string (i.e., "1, 2, 3"; your "runExperimenter" user command separates input by commas). Send those numbers and wait for a response. When you receive a response, send it to GA for evaluation. Have your GA perform its calculations. Once it's done and you have another 3 numbers to send, use those as input. Here's some pseudo code:

import GA

input_numbers = "1, 2, 3"
while True:
  send_to_flexsim(input_numbers)
  response = from_flexsim()
  GA.record_response()
  if GA.meets_stopping_criteria:
    break
  GA.evaluate()
  input_numbers = GA.new_input()

This won't compile, but it should give a good overview of some of the steps you should take in your socket-tcp.py to connect the two python scripts.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.