当前位置: 首页>>代码示例>>Python>>正文


Python problem.Problem类代码示例

本文整理汇总了Python中problem.Problem的典型用法代码示例。如果您正苦于以下问题:Python Problem类的具体用法?Python Problem怎么用?Python Problem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Problem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, fleet, environment, global_planner=None, options=None, **kwargs):
        Problem.__init__(self, fleet, environment, options, label='schedulerproblem')
        self.curr_state = self.vehicles[0].prediction['state'] # initial vehicle position
        self.goal_state = self.vehicles[0].poseT # overall goal
        self.problem_options = options  # e.g. selection of problem type (freeT, fixedT)
        if not 'freeT' in options:
            # select default type
            self.problem_options['freeT'] = True
        self.start_time = 0.
        self.update_times=[]

        # save vehicle dimension, determines how close waypoints can be to the border
        shape = self.vehicles[0].shapes[0]
        if isinstance(shape, Circle):
            self.veh_size = shape.radius
            # used to check if vehicle fits completely in a cell
            # radius is only half the vehicle size
            size_to_check = self.veh_size*2
        elif isinstance(shape, Rectangle):
            self.veh_size = max(shape.width, shape.height)
            # veh_size is complete width or height for rectangular shape
            size_to_check = self.veh_size
        # margin, applied to vehicle size to avoid goal positions very close to the border
        self.margin = 1.1

        # assign global planner
        if global_planner is not None:
            # save the provided planner
            self.global_planner = global_planner
        else:
            # make a default global planner
            self.global_planner = AStarPlanner(environment, [20, 20], self.curr_state, self.goal_state)

        # frame settings
        self.frames = []
        self.cnt = 1  # frame counter
        self.n_frames = options['n_frames'] if 'n_frames' in options else 1  # amount of frames to combine

        if (self.n_frames > 1 and not self.problem_options['freeT']):
            raise ValueError('Fixed time problems are only supported for n_frames = 1')
        self._n_frames = self.n_frames  # save original value
        self.frame_type = options['frame_type'] if 'frame_type' in options else 'shift'
        # set frame size for frame_type shift
        if self.frame_type is 'shift':
            # by default frame size is set to 1/5 of total environment width
            self.frame_size = options['frame_size'] if 'frame_size' in options else environment.room[0]['shape'].width*0.2
            # by default move limit is set to 1/4 of frame size
            self.move_limit = options['move_limit'] if 'move_limit' in options else self.frame_size*0.25
        if self.frame_type is 'corridor':
            # scale up frame with small steps or not
            self.scale_up_fine = options['scale_up_fine'] if 'scale_up_fine' in options else True
            self.l_shape = options['l_shape'] if 'l_shape' in options else False
        # check if vehicle size is larger than the cell size
        n_cells = self.global_planner.grid.n_cells
        if (size_to_check >= (min(environment.room[0]['shape'].width/float(n_cells[0]), \
                                  environment.room[0]['shape'].height/float(n_cells[1])))
           and self.frame_type == 'corridor'):
            warnings.warn('Vehicle is bigger than one cell, this may cause problems' +
                          ' when switching frames. Consider reducing the amount of cells or reducing' +
                          ' the size of the vehicle')
开发者ID:meco-group,项目名称:omg-tools,代码行数:60,代码来源:schedulerproblem.py

示例2: initData

def initData():
   """Load data and mappings from Raw data files and mapping files"""
   Patient.load()
   Med.load()
   Problem.load()
   Lab.load()
   Refill.load()
开发者ID:crb2nu,项目名称:smart_sample_patients,代码行数:7,代码来源:generate.py

示例3: testProblemStiffness

 def testProblemStiffness(self):
     width = 3
     height = 3
     [nodes, boundary_nodes, tris] = generateRectangularMesh((width, height), (0,0), (1,1))
     p = Problem(nodes, boundary_nodes, tris)
     stiffness = p.getStiffnessMatrix(lambda x,y: x*y).toarray()
     self.assertEqual(stiffness[0,0], 34.0/9.0)
开发者ID:tbenthompson,项目名称:elementsfun,代码行数:7,代码来源:testing.py

示例4: testKnownProblem

 def testKnownProblem(self):
     def f(x,y):
         return -2*x*y*(2*exp(2*x)*(x**2+y**2)+2*exp(2*x)*x)-(1+x**2*y)*(4*exp(2*x)*(x**2+y**2)+8*exp(2*x)*x+2*exp(2*x))-2*x**2*exp(2*x)*y-2*(1+x**2*y)*exp(2*x)
     
     def k(x,y):
         return 1+x**2*y
     
     def u(x,y):
         return exp(2*x)*(x**2+y**2)
     
     def ux(x,y):
         return 2*exp(2*x)*(x**2+y**2)+2*exp(2*x)*x
     
     def uy(x,y):
         return 2*exp(2*x)*y
         
     ewidth = 30
     eheight = 30
     xwidth = 2.
     ywidth = 2.
     ll = (-1.,-1.)
     
     [nodes, boundary_nodes, tris] = generateRectangularMesh((ewidth, eheight), ll, (xwidth/(ewidth-1),ywidth/(eheight-1)))
     p = Problem(nodes, boundary_nodes, tris)
     # U, g = p.solve(lambda x,y: cos(x*y*pi) - 0.5, lambda x,y: 1, lambda x,y: 0, ux)
     Uest, g = p.solve(f, k, u, ux)
     Utrue = [u(n.pos[0],n.pos[1]) for n in p.free_nodes] 
     # view_rectangular_grid_solution((ewidth, eheight), p, Uest, g)
     # view_rectangular_grid_solution((ewidth, eheight), p, Utrue, g)
     error = np.sqrt(np.sum((Utrue - Uest) ** 2))
     print error
     self.assertTrue(error < 0.5)
开发者ID:tbenthompson,项目名称:elementsfun,代码行数:32,代码来源:test_known_problem.py

示例5: generate_fake

    def generate_fake(self, paper):
        for i in range(3000):
            model = Problem()
            model.id = i
            model.difficulty = random.random()

            if i < 1001:
                model.type = 1
                model.score = paper.each_type_score[model.type-1] / \
                    paper.each_type_count[model.type-1]

            if i > 1000 and i < 2001:
                model.type = 2
                model.score = paper.each_type_score[model.type-1] / \
                    paper.each_type_count[model.type-1]

            if i > 2000 and i < 3001:
                model.type = 3
                model.score = paper.each_type_score[model.type-1] / \
                    paper.each_type_count[model.type-1]

            points = []
            # count = random.randint(1, 2)
            count = 1
            for j in range(count):
                points.append(random.randint(1, 10))

            model.points = points
            self.problem_db.append(model)
开发者ID:ts25504,项目名称:genetic-algorithm-py,代码行数:29,代码来源:db.py

示例6: reinitialize

 def reinitialize(self, father=None):
     if father is None:
         father = self.father
     Problem.reinitialize(self)
     for vehicle in self.vehicles:
         init = vehicle.get_init_spline_value()
         for k in range(vehicle.n_seg):
             father.set_variables(init[k], vehicle, 'splines_seg'+str(k))
开发者ID:meco-group,项目名称:omg-tools,代码行数:8,代码来源:point2point.py

示例7: testProblemGetDirichlet

 def testProblemGetDirichlet(self):
     width = 3
     height = 3
     [nodes, boundary_nodes, tris] = generateRectangularMesh((width, height), (0,0), (1,1))
     p = Problem(nodes, boundary_nodes, tris)
     data = p.getDirichletData(lambda x,y: x*y)
     self.assertEqual(data[0], 0)
     self.assertEqual(4 in data, True)
     self.assertEqual(2 in data, True)
开发者ID:tbenthompson,项目名称:elementsfun,代码行数:9,代码来源:testing.py

示例8: __init__

 def __init__(self, fleet, environment, n_frames, options=None):
     Problem.__init__(self, fleet, environment, options, label='multiframeproblem')
     self.n_frames = n_frames
     if self.n_frames > len(self.environment.room):
         raise RuntimeError('Number of frames you want to consider at once is larger' +
                            'than the amount of rooms provided in environment')
     self.init_time = None
     self.start_time = 0.
     self.objective = 0.
开发者ID:meco-group,项目名称:omg-tools,代码行数:9,代码来源:multiframeproblem.py

示例9: greedyBFS

 def greedyBFS(self):
     problemObj = Problem(self.initialState, self.boardValue, self.player)
     possibleStates = problemObj.possibleStates(self.initialState, self.player)
     stateCost = []
     for state in possibleStates:
         stateCost.append(problemObj.pathCost(state))
     nextState = possibleStates[stateCost.index(max(stateCost))]
     # self.printState(nextState)
     self.outputState(nextState)  # save output to a file.
开发者ID:pnisarg,项目名称:ninjaSquirrels-,代码行数:9,代码来源:problemSolver.py

示例10: test

def test():
    problem = Problem(
        id='6nXC7iyndcldO1dvKHbBmDHv',
        size=6, operators=frozenset(['not', 'shr4', 'shr16', 'shr1']))
    problem.solution = '(lambda (x_5171) (shr4 (shr16 (shr1 (not x_5171)))))'

    server = Server([problem])

    solve(problem, server)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2013-follow-up,代码行数:9,代码来源:solver_test.py

示例11: greedyBFSBattle

    def greedyBFSBattle(self, currentState, player):
        problemObj = Problem(currentState, self.boardValue, player)
        possibleStates = problemObj.possibleStates(currentState, player)
        stateCost = []
        for state in possibleStates:
            stateCost.append(problemObj.pathCost(state))

        nextState = possibleStates[stateCost.index(max(stateCost))]
        return nextState
开发者ID:pnisarg,项目名称:ninjaSquirrels-,代码行数:9,代码来源:problemSolver.py

示例12: simulate

 def simulate(self, current_time, simulation_time, sample_time):
     horizon_time = self.options['horizon_time']
     if self.init_time is None:
         rel_current_time = np.round(current_time-self.start_time, 6) % self.knot_time
     else:
         rel_current_time = self.init_time
     if horizon_time - rel_current_time < simulation_time:
         simulation_time = horizon_time - rel_current_time
     self.compute_partial_objective(current_time, simulation_time)
     Problem.simulate(self, current_time, simulation_time, sample_time)
开发者ID:meco-group,项目名称:omg-tools,代码行数:10,代码来源:point2point.py

示例13: construct

 def construct(self):
     self.T, self.t = self.define_parameter('T'), self.define_parameter('t')
     self.t0 = self.t/self.T
     Problem.construct(self)
     for vehicle in self.vehicles:
         splines = vehicle.define_splines(n_seg=1)
         vehicle.define_trajectory_constraints(splines[0], self.T)
         self.environment.define_collision_constraints(vehicle, splines, self.T)
     if len(self.vehicles) > 1 and self.options['inter_vehicle_avoidance']:
         self.environment.define_intervehicle_collision_constraints(self.vehicles, self.T)
开发者ID:meco-group,项目名称:omg-tools,代码行数:10,代码来源:point2point.py

示例14: __init__

 def __init__(self, index, vehicle, problem, environment, distr_problem,
              options={}):
     Problem.__init__(self, vehicle, environment, options, label='admm')
     self.problem = problem
     self.distr_problem = distr_problem
     self.vehicle = vehicle
     self.environment = environment
     self.group = {child.label: child for child in ([
         vehicle, problem, environment, self] + environment.obstacles)}
     for child in self.group.values():
         child._index = index
开发者ID:jgillis,项目名称:omg-tools,代码行数:11,代码来源:admm.py

示例15: __init__

 def __init__(self, index, vehicle, problem, environment, distr_problem,
              label, options=None):
     Problem.__init__(self, vehicle, environment, options, label=label)
     self.problem = problem
     self.distr_problem = distr_problem
     self.vehicle = vehicle
     self.environment = environment
     self.group = col.OrderedDict()
     for child in ([vehicle, problem, environment, self] + environment.obstacles):
         self.group[child.label] = child
     for child in self.group.values():
         child._index = index
开发者ID:meco-group,项目名称:omg-tools,代码行数:12,代码来源:dualmethod.py


注:本文中的problem.Problem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。