为C ++构建Lua(Building Lua for C++)
根据Lua Wiki,如果将Lua 5.1或更高版本编译为C ++,它将使用C ++异常。 由于Lua是一个C库,它只引用makefile中的CC。 所以,我的想法是将CC重新定义为“g ++”,因此我不必修改makefile。
make generic CC="g++"
我能够毫无问题地构建Lua。 但是,现在当我将C ++应用程序链接到Lua(静态)库时,我收到许多Lua函数的未定义引用错误(lua_checklstring,lua_pushinteger等)。
当我使用gcc构建Lua时,我的应用程序链接成功。
make generic CC="gcc"
我是否错误地编译Lua for C ++? 我假设我需要以某种方式使用g ++,因为Lua源代码包含对cplusplus的预处理器检查以确定是否应该启用C ++异常。
According to the Lua Wiki, if Lua 5.1 or later is compiled as C++, it will use C++ exceptions. Since Lua is a C library it only references CC in the makefile. So, my idea was to redefine CC as "g++" so I don't have to modify the makefile.
make generic CC="g++"
I was able to build Lua without any problems. However, now when I link my C++ application to the Lua (static) library I receive undefined reference errors for many Lua functions (lua_checklstring, lua_pushinteger, etc).
When I build Lua using using gcc my application links successfully.
make generic CC="gcc"
Am I compiling Lua for C++ incorrectly? I assume I need to use g++ somehow since the Lua source code contains preprocessor checking for cplusplus to determine if C++ exceptions should be enabled.
原文:https://stackoverflow.com/questions/20839883
最满意答案
使用不可能的基于渐变的优化器。 您需要使用无梯度方法。 与OpenMDAO 2.2相比,没有任何内置的方法来实施这种离散化。 您需要在问题类周围使用外部循环才能使其工作。
这是一个简单的例子:
import numpy as np from openmdao.api import Problem, ScipyOptimizeDriver, ExecComp, IndepVarComp # build the model prob = Problem() indeps = prob.model.add_subsystem('indeps', IndepVarComp()) indeps.add_output('x', 3.0) indeps.add_output('y', -4.0) prob.model.add_subsystem('paraboloid', ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3')) prob.model.connect('indeps.x', 'paraboloid.x') prob.model.connect('indeps.y', 'paraboloid.y') # setup the optimization prob.driver = ScipyOptimizeDriver() prob.driver.options['optimizer'] = 'SLSQP' prob.model.add_design_var('indeps.y', lower=-50, upper=50) prob.model.add_objective('paraboloid.f') prob.setup() for x in np.arange(-10,12,2): prob['indeps.x'] = x # could call just run_model if no optimization was desired #prob.run_model() # for each value of x, optimize for y prob.run_driver() # minimum value print(prob['paraboloid.f']) # location of the minimum print(prob['indeps.x']) print(prob['indeps.y'])
Using a gradient based optimizer that is not possible. You would need to use a gradient free method. As over OpenMDAO 2.2 there is not any built in way to enforce that kind of discretization. You would need to use an external loop around the problem class to get that to work.
Here is a simple example:
import numpy as np from openmdao.api import Problem, ScipyOptimizeDriver, ExecComp, IndepVarComp # build the model prob = Problem() indeps = prob.model.add_subsystem('indeps', IndepVarComp()) indeps.add_output('x', 3.0) indeps.add_output('y', -4.0) prob.model.add_subsystem('paraboloid', ExecComp('f = (x-3)**2 + x*y + (y+4)**2 - 3')) prob.model.connect('indeps.x', 'paraboloid.x') prob.model.connect('indeps.y', 'paraboloid.y') # setup the optimization prob.driver = ScipyOptimizeDriver() prob.driver.options['optimizer'] = 'SLSQP' prob.model.add_design_var('indeps.y', lower=-50, upper=50) prob.model.add_objective('paraboloid.f') prob.setup() for x in np.arange(-10,12,2): prob['indeps.x'] = x # could call just run_model if no optimization was desired #prob.run_model() # for each value of x, optimize for y prob.run_driver() # minimum value print(prob['paraboloid.f']) # location of the minimum print(prob['indeps.x']) print(prob['indeps.y'])
相关问答
更多-
问题是这一行 root.add('childWeight', IndepVarComp('x',240)) 你已经创建了一个整数变量。 试试这个: root.add('childWeight', IndepVarComp('x',240.)) 如果您想使用有限差分,您还需要: top.root.fd_options['force_fd'] = True The problem is this line root.add('childWeight', IndepVarComp('x',240)) Yo ...
-
使用不可能的基于渐变的优化器。 您需要使用无梯度方法。 与OpenMDAO 2.2相比,没有任何内置的方法来实施这种离散化。 您需要在问题类周围使用外部循环才能使其工作。 这是一个简单的例子: import numpy as np from openmdao.api import Problem, ScipyOptimizeDriver, ExecComp, IndepVarComp # build the model prob = Problem() indeps = prob.model.add_su ...
-
OpenMDAO奇异条目(OpenMDAO Singular Entry)[2022-06-05]
我意识到单行的原因是我没有定义组件的偏导数。 我通过将命令declare_partials添加到顶层系统来解决此问题。 回溯给了我线索与线性化有关的线索。 单数列的情况似乎与我在apply_nonlinear有两个方程,但只有一个未知( z )有关。 I realized that the cause for the singular row was that I had not defined the partial derivatives for the component. I fixed this ... -
你是对的,因为Problem不是一个OpenMDAO组件而且没有一个solve_nonlinear方法,所以Problem的solve_nonlinear永远不会被调用。 为了在另一个问题中运行子模型问题,您想要做的是将其封装在Component实例中。 它看起来像这样: class SubOptimization(Component) def __init__(self): super(SubOptimization, self).__init__() # In ...
-
您键入的代码中有两个缺少的括号,但这些必须来自将其转录到此处。 您缺少的主要内容是ExecComp的额外参数,以便它知道如何调整传入的x的大小。 import numpy as np from openmdao.api import Problem, Group, IndepVarComp, ExecComp prob = Problem() prob.root = root = Group() root.add('p1', IndepVarComp('x', np.array([3, 7, 5], ...
-
我想到了。 在大脑放屁的经典时刻,我忘了将我的设计变量和目标函数添加到驱动程序中。 像这样的东西是我想念的东西: top.driver = ScipyOptimizer() top.driver.options['optimizer'] = 'SLSQP' top.driver.add_desvar('p1.x', lower=-50, upper=50) top.driver.add_desvar('p2.y', lower=-50, upper=50) top.driver.add_objective ...
-
您可以使用新的css样式-fx-color更改-fx-color 。 progressIndicator.setStyle("-fx-color: red;"); You can change the color by using a new css style -fx-color. progressIndicator.setStyle("-fx-color: red;");
-
因为你打电话时没有做任何变量促销 sellars.add(name, AEPGroup(nTurbines=nTurbines, nDirections=nDirections, differentiable=True, use_rotor_components=False)) 您可以将变量名称设置为 prob['sellars.sella ...
-
在OpenMDAO中将这样的东西设置为单个单片模型实际上是不可能的。 到目前为止,最简单的方法是使用三个单独的问题实例。 高保真问题 低保真度问题 低传输函数问题(可选) 您将使用前两个问题实例来计算分析结果和渐变。 第三个问题可能是可选的,因为我希望它更简单,并且可以通过简单的功能手动实现。 我会编写一个标准的python脚本来循环你的伪代码建议的方式。 因此,您将使用OpenMDAO来构建分析模型并从中获取衍生物更加简单。 但是然后围绕它构建一个自定义python脚本来实现你的AMMF。 至于拉格朗日乘 ...
-
在您的产品模型中,确保在getProducts($data = array())中获取stock_status_id ,然后它将返回预期结果。 In your product model, make sure you are fetching stock_status_id in getProducts($data = array()), then it will return expected result.