|
6 | 6 | # A basic chicken swarm optimization class. |
7 | 7 | # |
8 | 8 | # Author(s): Lauren Linkous, Jonathan Lundquist |
9 | | -# Last update:june 19, 2025 |
| 9 | +# Last update:June 28, 2025 |
10 | 10 | ##--------------------------------------------------------------------\ |
11 | 11 |
|
12 | 12 |
|
@@ -69,13 +69,13 @@ def __init__(self, lbound, ubound, targets,E_TOL, maxit, |
69 | 69 |
|
70 | 70 |
|
71 | 71 | #unpack the opt_df standardized vals |
72 | | -boundary=opt_df['BOUNDARY'][0] |
73 | | -RN=opt_df['RN'][0] |
74 | | -HN=opt_df['HN'][0] |
75 | | -MN=opt_df['MN'][0] |
76 | | -CN=opt_df['CN'][0] |
77 | | -G=opt_df['G'][0] |
78 | | -NO_OF_PARTICLES=RN+HN+MN+CN |
| 72 | +boundary=int(opt_df['BOUNDARY'][0]) |
| 73 | +RN=int(opt_df['RN'][0]) |
| 74 | +HN=int(opt_df['HN'][0]) |
| 75 | +MN=int(opt_df['MN'][0]) |
| 76 | +CN=int(opt_df['CN'][0]) |
| 77 | +G=int(opt_df['G'][0]) |
| 78 | +NO_OF_PARTICLES=RN+HN+MN+CN |
79 | 79 |
|
80 | 80 |
|
81 | 81 | heightl=np.shape(lbound)[0] |
@@ -702,51 +702,95 @@ def step(self, suppress_output): |
702 | 702 | self.debug_message_printout(msg) |
703 | 703 |
|
704 | 704 | defexport_swarm(self): |
705 | | -swarm_export= {'lbound':self.lbound, |
706 | | -'ubound':self.ubound, |
707 | | -'M':self.M, |
708 | | -'V':self.V, |
709 | | -'Gb':self.Gb, |
710 | | -'F_Gb':self.F_Gb, |
711 | | -'Pb':self.Pb, |
712 | | -'F_Pb':self.F_Pb, |
713 | | -'targets':self.targets, |
714 | | -'maxit':self.maxit, |
715 | | -'E_TOL':self.E_TOL, |
716 | | -'iter':self.iter, |
717 | | -'current_particle':self.current_particle, |
718 | | -'number_of_particles':self.number_of_particles, |
719 | | -'allow_update':self.allow_update, |
720 | | -'Flist':self.Flist, |
721 | | -'Fvals':self.Fvals, |
722 | | -'Active':self.Active, |
723 | | -'Boundary':self.boundary, |
724 | | -'Mlast':self.Mlast} |
| 705 | +#These do NOT export. |
| 706 | +# # These are passed objects created at runtim |
| 707 | +# self.parent # this is an object in memory at runtime |
| 708 | +# self.surrogateOptimizer = # this is an object in memory at runtime |
| 709 | +# self.obj_func = # this is an object in memory at runtime |
| 710 | +# self.constr_func = # this is an object in memory at runtime |
| 711 | +# self.useSurrogateModel = # this NEEDS to match every time. Should be part of the init() |
| 712 | +# self.number_decimals = # this can be changed. IT might be interesting to change between runs |
| 713 | +# self.boundary = boundary # int. can be chaged, but needs a default |
| 714 | +# These export: |
| 715 | + |
| 716 | + |
| 717 | +swarm_export= { |
| 718 | +# These are values that define the swarm and current solution space |
| 719 | +# These are retained because the dimensionality of M, F_pb, etc. are strict |
| 720 | +'evaluate_threshold': [self.evaluate_threshold], |
| 721 | +'obj_threshold': [self.obj_threshold], |
| 722 | +'targets': [self.targets], |
| 723 | +'lbound': [self.lbound], |
| 724 | +'ubound': [self.ubound], |
| 725 | +'output_size': [self.output_size],# this can be calculated if needed |
| 726 | +# convergence and step criteria |
| 727 | +'maxit': [self.maxit], |
| 728 | +'E_TOL': [self.E_TOL], |
| 729 | +'iter': [self.iter], |
| 730 | +'current_particle': [self.current_particle], |
| 731 | +'allow_update': [self.allow_update], |
| 732 | +# optimizer specfic |
| 733 | +'RN': [self.RN], |
| 734 | +'HN': [self.HN], |
| 735 | +'MN': [self.MN], |
| 736 | +'CN': [self.CN], |
| 737 | +'G': [self.G], |
| 738 | +'number_of_particles': [self.number_of_particles], |
| 739 | +# shared format vars for AntennaCAT set |
| 740 | +'M': [self.M], |
| 741 | +'Active': [self.Active], |
| 742 | +'Gb': [self.Gb], |
| 743 | +'F_Gb': [self.F_Gb], |
| 744 | +'Pb': [self.Pb], |
| 745 | +'F_Pb': [self.F_Pb], |
| 746 | +'Flist': [self.Flist], |
| 747 | +'Fvals': [self.Fvals], |
| 748 | +'Mlast': [self.Mlast] |
| 749 | + } |
725 | 750 |
|
726 | | -returnswarm_export |
727 | | - |
728 | | -defimport_swarm(self,swarm_export,obj_func): |
729 | | -self.lbound=swarm_export['lbound'] |
730 | | -self.ubound=swarm_export['ubound'] |
731 | | -self.M=swarm_export['M'] |
732 | | -self.V=swarm_export['V'] |
733 | | -self.Gb=swarm_export['Gb'] |
734 | | -self.F_Gb=swarm_export['F_Gb'] |
735 | | -self.Pb=swarm_export['Pb'] |
736 | | -self.F_Pb=swarm_export['F_Pb'] |
737 | | -self.targets=swarm_export['targets'] |
738 | | -self.maxit=swarm_export['maxit'] |
739 | | -self.E_TOL=swarm_export['E_TOL'] |
740 | | -self.iter=swarm_export['iter'] |
741 | | -self.current_particle=swarm_export['current_particle'] |
742 | | -self.number_of_particles=swarm_export['number_of_particles'] |
743 | | -self.allow_update=swarm_export['allow_update'] |
744 | | -self.Flist=swarm_export['Flist'] |
745 | | -self.Fvals=swarm_export['Fvals'] |
746 | | -self.Active=swarm_export['Active'] |
747 | | -self.boundary=swarm_export['Boundary'] |
748 | | -self.Mlast=swarm_export['Mlast'] |
749 | | -self.obj_func=obj_func |
| 751 | +returnswarm_export# this is turned into a dataframe in the driver class |
| 752 | + |
| 753 | +defimport_swarm(self,swarm_export): |
| 754 | + |
| 755 | +# swarm export is a dataframe. this is unpacked and converted just like |
| 756 | +# with the initialized opt_df params |
| 757 | + |
| 758 | +# These are values that define the swarm and current solution space |
| 759 | +# These are retained because the dimensionality of M, F_pb, etc. are strict |
| 760 | +self.evaluate_threshold=bool(swarm_export['evaluate_threshold'][0]) |
| 761 | +self.obj_threshold=np.array(swarm_export['obj_threshold'][0]) |
| 762 | +self.targets=np.array(swarm_export['targets'][0]).reshape(-1,1) |
| 763 | + |
| 764 | +self.lbound=np.array(swarm_export['lbound'][0]) |
| 765 | +self.ubound=np.array(swarm_export['ubound'][0]) |
| 766 | +self.output_size=int(swarm_export['output_size'][0])# this can be calculated if needed |
| 767 | +# convergence and step criteria |
| 768 | +self.maxit=int(swarm_export['maxit'][0]) |
| 769 | +self.E_TOL=float(swarm_export['E_TOL'][0]) |
| 770 | +self.iter=int(swarm_export['iter'][0])# NEED 'RESUME' and 'START OVER' options |
| 771 | +self.current_particle=int(swarm_export['current_particle'][0]) |
| 772 | +self.allow_update=int(swarm_export['allow_update'][0])# BOOL as INT |
| 773 | + |
| 774 | +# optimizer specfic |
| 775 | +self.RN=int(swarm_export['RN'][0]) |
| 776 | +self.HN=int(swarm_export['HN'][0]) |
| 777 | +self.MN=int(swarm_export['MN'][0]) |
| 778 | +self.CN=int(swarm_export['CN'][0]) |
| 779 | +self.G=int(swarm_export['G'][0]) |
| 780 | +self.number_of_particles=int(swarm_export['number_of_particles'][0]) |
| 781 | + |
| 782 | +# shared format vars for AntennaCAT set |
| 783 | + |
| 784 | +self.M=np.array(swarm_export['M'][0]) |
| 785 | +self.Active=np.array(swarm_export['Active'][0]) |
| 786 | +self.Gb=np.array(swarm_export['Gb'][0]) |
| 787 | +self.F_Gb=np.array(swarm_export['F_Gb'][0]) |
| 788 | +self.Pb=np.array(swarm_export['Pb'][0]) |
| 789 | +self.F_Pb=np.array(swarm_export['F_Pb'][0]) |
| 790 | +self.Flist=np.array(swarm_export['Flist'][0]) |
| 791 | +self.Fvals=np.array(swarm_export['Fvals'][0]) |
| 792 | +self.Mlast=np.array(swarm_export['Mlast'][0]) |
| 793 | + |
750 | 794 |
|
751 | 795 | defget_obj_inputs(self): |
752 | 796 | returnnp.vstack(self.M[self.current_particle]) |
|