Ejemplo n.º 1
0
def do_first(sobol_seq=None, ellist=None):

    if sobol_seq is None:
        sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
    if ellist is None:
        ellist = [BulbDepth, CBulbMid, CBulbBlock]
    ith = -1
    #x=.5
    redo = []
    #last_valid = None
    for i in range(len(ellist)):
        x = sobol_seq.next()
        var = ellist[i]
        mk_name, mk_val = rgp.get_name_and_value(var)
        print mk_name, mk_val
        val = mk_val[ith].getpoint(x)
        value = ia(val, val)
        var = var == value
        #-----------------------------------------
        ret_state = copy.copy(rgp.env)
        rgp.add_one_rule(var, var.name)
        rgp.compute_fresh_rules_graph()
        #-----------------------------------------

        if len(rgp.env.states) == 0:
            #rgp.nodes.pop()
            #rgp.env = ret_state
            rgp.reset(ret_state, var)
            #rgp.env.states = ret_state.states
            redo.append(var)
            #last_valid = ret_state
        else:
            if rgp._verbose: print 'done ', mk_name, '=>', value
    return rgp, redo, None, sobol_seq
 def __init__(self, spec, verbose=False):
     self._verbose = verbose
     self.spec = spec
     self.sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
     #alternatvely, initialize a true IA hull
     self.hdp = hullclp()  #hull_use_HICLP.hullclp()
     self.hdp.lwl = ia(spec.lwl[0], spec.lwl[1])
     self.hdp.draft = ia(spec.draft[0], spec.draft[1])
     self.hdp.bwl = ia(spec.bwl[0], spec.bwl[1])
     self.hdp.vol = ia(spec.vol[0], spec.vol[1])
     self.hdp.Cb = ia(spec.Cb[0], spec.Cb[1])
     self.hdp.Cwp = ia(spec.Cwp[0], spec.Cwp[1])
     self.hdp.Ccp = ia(spec.Ccp[0], spec.Ccp[1])
     self.hdp.LCG = ia(spec.LCG[0], spec.LCG[1])
     self.hdp.Cmidshp = ia(spec.Cmidshp[0], spec.Cmidshp[1])
     self.hdp.AC_revise()
     #"""
     self.hdp.states = self.hdp.shape_bow_section_inizers()
     self.hdp.states = self.hdp.shape_stern_section_inizers()
     self.hdp.states = self.hdp.SAC_run_area_ini()
     self.hdp.states = self.hdp.SAC_Xc_init()
     self.hdp.states = self.hdp.LCG_constraints()
     #"""
     self.hdp.AC_revise()
     self.feasible_designs = []
     self.infeasible_designs = []
 def generate_quasirandom_sequence(self, allow_range):
     s1 = sobol.sobolSeq([1, 1], [1, 1])
     inf = allow_range[0]
     sup = allow_range[1]
     r = sup - inf
     x = np.asarray([next(s1) for _ in range(self.N)])
     return r * x + inf
Ejemplo n.º 4
0
    def __init__(self,
                 ship_beam=None,
                 ship_depth=None,
                 ship_Lpp=None,
                 ship_Amshp=None,
                 ship_Acp=None,
                 ship_Awp=None,
                 ship_Vol=None,
                 bare_hull=None):

        self.init_ship_beam = ship_beam
        self.init_ship_depth = ship_depth
        self.init_ship_Lpp = ship_Lpp
        self.init_ship_Amshp = ship_Amshp
        self.init_ship_Acp = ship_Acp
        self.init_ship_Awp = ship_Awp
        self.init_ship_Vol = ship_Vol
        self.bare_hull = bare_hull  # sqKanren States() processed by opt_simple_hull

        self.rgp = RulesGraphProcessor(verbose=False)
        self.sobol_seq = sobol.sobolSeq([1, 1], [1, 1])

        if bare_hull is None:
            self = setup_dummy_bare_hull(self)
            self.rgp.compute_fresh_rules_graph()
        else:
            self.initialize_ship_parameters_and_values()
        #        self.rgp = self.initialize_bulb_parameters(self.rgp)
        #        self.rgp = self.coupling_constants(self.rgp)
        #
        #        self.rgp = self.linear_parameters(self.rgp)
        #        self.rgp = self.nonlinear_parameters(self.rgp)
        #
        #
        #        self.initialize_lists()
        #        self.rgp = ini_coeffs(self.Coefficients, self.rgp)

        #self.rgp = self.experiment_bulb_parameters(self.rgp)
        #self.rgp = self.basic_bulb_rules(self.rgp)

        self.initialize_bulb_parameters()
        self.coupling_constants()

        self.linear_parameters()
        self.nonlinear_parameters()

        self.initialize_lists()
        self = ini_coeffs(self)  #.Coefficients, self.rgp)
        self.experiment_bulb_parameters()
        self.basic_bulb_rules()
    def __init__(self,
                 ship_beam=None,
                 ship_depth=None,
                 ship_Lpp=None,
                 ship_Amshp=None,
                 ship_Acp=None,
                 ship_Awp=None,
                 ship_Vol=None,
                 bare_hull=None):
        self.nCV = 7
        self.idealdict = {}  #this will eventually store primary bulb curves
        self.init_ship_beam = ship_beam
        self.init_ship_depth = ship_depth
        self.init_ship_Lpp = ship_Lpp
        self.init_ship_Amshp = ship_Amshp
        self.init_ship_Acp = ship_Acp
        self.init_ship_Awp = ship_Awp
        self.init_ship_Vol = ship_Vol
        self.bare_hull = bare_hull  # sqKanren States() processed by opt_simple_hull

        self.rgp = RulesGraphProcessor(verbose=False)
        self.sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
        self.tol = 1.e-4
        self.verbose = True
        if bare_hull is None:
            self = setup_dummy_bare_hull(self)
            self.rgp.compute_fresh_rules_graph()
        else:
            self.initialize_ship_parameters_and_values()

        self.initialize_bulb_parameters()
        self.coupling_constants()

        self.linear_parameters()
        self.nonlinear_parameters()

        self.initialize_lists()
        self = ini_coeffs(self)  #.Coefficients, self.rgp)

        self.experiment_bulb_parameters()  #add new rules here
        self.basic_bulb_rules()
    def __init__(self,
                 ship_beam=None,
                 ship_depth=None,
                 ship_Lpp=None,
                 ship_Amshp=None,
                 ship_Acp=None,
                 ship_Awp=None,
                 ship_Vol=None,
                 bare_hull=None):

        self.init_ship_beam = ship_beam
        self.init_ship_depth = ship_depth
        self.init_ship_Lpp = ship_Lpp
        self.init_ship_Amshp = ship_Amshp
        self.init_ship_Acp = ship_Acp
        self.init_ship_Awp = ship_Awp
        self.init_ship_Vol = ship_Vol
        self.bare_hull = bare_hull  # sqKanren States() processed by opt_simple_hull

        self.rgp = RulesGraphProcessor(verbose=False)
        self.sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
Ejemplo n.º 7
0
        #
        rgp.compute_fresh_rules_graph()
    #    #
    #    ##
    #    ##************************************* end linear relations
    #    ##
    #
    #
    #    print '\n\n state after:'
    #    #print st
    #
    #    print rgp.env

    if final_test:
        self = rgp
        sbs = sobol.sobolSeq([1, 1], [1, 1])
        redo = None

        ellist = [CBulbMid]
        rgp, redo, last_valid, sbs = do_first(sbs, ellist)
        rgp, redo, last_valid, sbs = do_first(sbs, redo)

        ellist = [CBulbBlock]
        rgp, redo, last_valid, sbs = do_first(sbs, ellist)
        rgp, redo, last_valid, sbs = do_first(sbs, redo)

        ellist = [BulbDepth]
        rgp, redo, last_valid, sbs = do_first(sbs, ellist)
        rgp, redo, last_valid, sbs = do_first(sbs, redo)

        ellist = [A_mid]
Ejemplo n.º 8
0
def older_test():
    print 'Kraft Bulbous Bow Parameters'
    print '\n Linear Parameters:'

    ##
    ##************************************* bulb
    ##
    A_mid = lp.PStates(name='A_mid')
    A_lateral = lp.PStates(name='A_lateral')
    #A_flat = lp.PStates(name='A_flat')  #BBwl instead
    A_BBwl = lp.PStates(name='A_BBwl')

    #use the principle of the minimum square enclosing box (cartesian b/c ia is cartesian)
    BulbBeam = lp.PStates(name='BulbBeam')  #Bulb half beam
    BulbDepth = lp.PStates(name='BulbDepth')  #Bulb depth
    BulbLength = lp.PStates(
        name='BulbLength')  #Bulb max length (min square enclosing box length)

    BulbVolume = lp.PStates(name='BulbVolume')

    CBulbMid = lp.PStates(name='CBulbMid')  #Bulb midsection coefficient
    CBulbCtrPln = lp.PStates(
        name='CBulbCtrPln')  #Bulb centerplane profile area coefficient
    CBulbWtrPln = lp.PStates(
        name='CBulbWtrPln')  #Bulb waterplane area coefficient

    CBulbBlock = lp.PStates(name='CBulbBlock')
    CBulbPrismatic = lp.PStates(name='CBulbPrismatic')

    #TODO: fix this with class to construct rules graph!

    A_mid = A_mid == ia(10., 20.)  #issue: order of assignment "matters"
    BulbBeam = BulbBeam == ia(5., 10.)
    CBulbMid = CBulbMid == ia(.5, 1.)
    CBulbWtrPln = CBulbWtrPln == ia(.5, 1.)
    #BulbDepth = BulbDepth == ia(-10.1,10.)

    rgp = RulesGraphProcessor()
    #"""

    #rgp.add_one_rule(BulbDepth,'BulbDepth')
    rgp.add_one_rule(A_mid, 'A_mid')
    rgp.add_one_rule(BulbBeam, 'BulbBeam')
    rgp.add_one_rule(CBulbMid, 'CBulbMid')
    rgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')
    #rgp.add_one_rule(BulbDepth,'BulbDepth') #should not older_testbe needed!

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    #rgp.AC_revise()
    #rgp.env

    ##
    ##************************************* end bulb
    ##

    ##
    ##************************************* ship
    ##
    ship_beam = lp.PStates(name='ship_beam')
    # note: could use bare_hull var names instead.
    #       e.g. lp.PStates(name=self.init_ship_beam.name)
    ship_depth = lp.PStates(name='ship_depth')
    ship_Lpp = lp.PStates(name='ship_Lpp')
    #
    #quantities of m**2
    ship_Amshp = lp.PStates(name='ship_Amshp')
    ship_Acp = lp.PStates(name='ship_Acp')
    ship_Awp = lp.PStates(name='ship_Awp')
    #
    #quantities of m**3
    ship_Vol = lp.PStates(name='ship_Vol')

    #-----------------------------------------
    # set the ship values in the bulb environement:
    ship_beam = ship_beam == ia(17.4663142374, 17.4663142374)

    ship_depth = ship_depth == ia(16.2051841085, 16.2051841085)

    ship_Lpp = ship_Lpp == ia(111.099919763, 111.099919763)

    ship_Amshp = ship_Amshp == ia(261.639572047, 261.639572047)

    ship_Acp = ship_Acp == ia(1656.36308186, 1656.36308186)

    ship_Awp = ship_Awp == ia(1736.75296874, 1736.75296874)

    ship_Vol = ship_Vol == ia(27043.7825521, 27043.7825521)
    #-----------------------------------------

    #-----------------------------------------
    rgp.add_one_rule(ship_beam, 'ship_beam')
    rgp.add_one_rule(ship_depth, 'ship_depth')
    rgp.add_one_rule(ship_Lpp, 'ship_Lpp')
    rgp.add_one_rule(ship_Amshp, 'ship_Amshp')
    rgp.add_one_rule(ship_Acp, 'ship_Acp')
    rgp.add_one_rule(ship_Awp, 'ship_Awp')
    rgp.add_one_rule(ship_Vol, 'ship_Vol')
    #-----------------------------------------
    ##
    ##************************************* end ship
    ##
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    ##
    ##************************************* bulb rules
    ##
    """-----------------------------------------------
    Rule:  Midbulb_Area < max_Beam * max_Depth
    CBulbMid -> [0.,1.]
    CBulbMid ==  A_mid/(BulbBeam*BulbDepth)
    """
    CBulbMid = CBulbMid == A_mid / (BulbBeam * BulbDepth)
    """-----------------------------------------------
    Rule: z-y_area < max_length * max_Depth
    """
    CBulbCtrPln = CBulbCtrPln == A_lateral / (BulbLength * BulbDepth)
    """-----------------------------------------------
    Rule: wL_area < max_length * max_Depth
    """
    #CBulbWtrPln = CBulbWtrPln == A_BBwl/(BulbLength*BulbDepth)
    CBulbWtrPln = CBulbWtrPln == A_BBwl / (BulbLength * BulbBeam)

    #2 more rules!
    """-----------------------------------------------
    Rule: Bulb_vol < max_length * max_Depth * max *BulbBeam
    """
    CBulbBlock = CBulbBlock == BulbVolume / (BulbLength * BulbDepth * BulbBeam)
    #
    """-----------------------------------------------
    Rule: Bulb_vol < max_length * mid_bulb_area
    """
    CBulbPrismatic = CBulbPrismatic == BulbVolume / (BulbLength * A_mid)
    #

    rgp.add_one_rule(CBulbMid, 'CBulbMid')
    rgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')
    rgp.add_one_rule(CBulbWtrPln, 'CBulbWtrPln')

    rgp.add_one_rule(CBulbBlock, 'CBulbBlock')
    rgp.add_one_rule(CBulbPrismatic, 'CBulbPrismatic')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #"""

    #BulbLength  = BulbLength == ia(10.,15.)
    BulbLength = BulbLength == ia(1., 15.)
    #CBulbCtrPln = CBulbCtrPln == ia(.5,1.)
    CBulbCtrPln = CBulbCtrPln == ia(0., 1.)
    rgp.add_one_rule(BulbLength, 'BulbLength')
    rgp.add_one_rule(CBulbCtrPln, 'CBulbCtrPln')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    #BulbDepth = BulbDepth == ia(1.,10.)
    BulbDepth = BulbDepth == ia(5., 10.)
    rgp.add_one_rule(BulbDepth, 'BulbDepth')

    CBulbBlock = CBulbBlock == ia(0., 1.)
    CBulbPrismatic = CBulbPrismatic == ia(0., 1.)
    rgp.add_one_rule(BulbLength, 'CBulbBlock')
    rgp.add_one_rule(CBulbPrismatic, 'CBulbPrismatic')

    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()

    ##
    ##************************************* end bulb rules
    ##

    ##
    ##************************************* Ship to Bulb Coefficients
    ##
    #
    #linear
    #-----------------------------------------
    Cbb = lp.PStates(name='Cbb')
    Clpr = lp.PStates(name='Clpr')
    Czb = lp.PStates(name='Czb')
    #
    #nonlinear
    #-----------------------------------------
    Cabt = lp.PStates(name='Cabt')
    Cabl = lp.PStates(name='Cabl')
    Cvpr = lp.PStates(name='Cvpr')
    #
    ##
    ##************************************* end Ship to Bulb Coefficients
    ##

    ##
    ##************************************* nonlinear relations
    ##
    #Kracht nonlinear relations:
    Cabt = Cabt == A_mid / ship_Amshp
    Cabl = Cabl == A_lateral / ship_Acp  #departure from Kracht
    Cvpr = Cvpr == BulbVolume / ship_Vol
    #
    """
    rgp.add_one_rule( Cbb, 'Cbb')
    rgp.add_one_rule(Clpr, 'Clpr')
    rgp.add_one_rule( Czb, 'Czb')
    #"""
    #
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #
    ##
    ##************************************* end nonlinear relations
    ##

    ##
    ##************************************* linear relations
    ##
    #Kracht linear relations:
    Cbb = Cbb == BulbBeam / ship_beam
    Clpr = Clpr == BulbLength / ship_Lpp
    Czb = Czb == BulbLength / ship_depth
    #
    """
    rgp.add_one_rule( Cbb, 'Cbb')
    rgp.add_one_rule(Clpr, 'Clpr')
    rgp.add_one_rule( Czb, 'Czb')
    #"""
    #
    rgp.compute_fresh_rules_graph()
    #rgp.compute_rules_graph()
    #
    ##
    ##************************************* end linear relations
    ##

    print '\n\n state after:'
    #print st

    print rgp.env

    ellist = [
        BulbDepth,
        CBulbMid,
        CBulbBlock,
        BulbBeam,
        BulbLength,
        BulbVolume,
        #A_mid,
        #A_lateral,
        #A_BBwl,
        CBulbCtrPln,
        CBulbWtrPln,
        CBulbPrismatic
    ]

    sobol_seq = sobol.sobolSeq([1, 1], [1, 1])
    ith = -1
    #x=.5
    redo = []
    for i in range(len(ellist)):
        x = sobol_seq.next()
        var = ellist[i]
        mk_name, mk_val = rgp.get_name_and_value(var)
        print mk_name, mk_val
        val = mk_val[ith].getpoint(x)
        value = ia(val, val)
        var = var == value
        #-----------------------------------------
        ret_state = copy.copy(rgp.env)
        rgp.add_one_rule(var, var.name)
        rgp.compute_fresh_rules_graph()
        #rgp.compute_rules_graph()
        #-----------------------------------------

        if len(rgp.env.states) == 0:
            rgp.env = ret_state
            #rgp.env.states = ret_state.states
            redo.append(var)
        else:
            if rgp._verbose: print 'done ', mk_name, '=>', value

    def checker():
        print '\n CBulbMid'
        print gv(A_mid) / (gv(BulbBeam) * gv(BulbDepth))
        print gv(CBulbMid)

        print '\n CBulbCtrPln'
        print gv(A_lateral) / (gv(BulbLength) * gv(BulbDepth))
        print gv(CBulbCtrPln)

        print '\n CBulbWtrPln'
        print gv(A_BBwl) / (gv(BulbLength) * gv(BulbBeam))
        print gv(CBulbWtrPln)

        print '\n CBulbBlock'
        print gv(BulbVolume) / (gv(BulbLength) * gv(BulbBeam) * gv(BulbDepth))
        print gv(CBulbBlock)

        print '\n CBulbPrismatic'
        print gv(BulbVolume) / (gv(BulbLength) * gv(A_mid))
        print gv(CBulbPrismatic)
        return

    def gv(var):
        return rgp.get_name_and_value(var)[1][0]

    checker()
    return redo, rgp