使用约束编程优化

时间:2015-05-22 06:48:23

标签: optimization constraint-programming nonlinear-optimization minizinc

我想用约束编程语言表达和解决下面的方程式。

我有变量t并且试图找到最佳乘数k,这最小化了我的目标函数。

时间:输入中给出的t1,t2,t3 ......

Multipler k1,k2,k3 ...(这是需要找到的连续变量)

c1,c2,.. cN是常数

主方程k1 * sin(c1 * x)+ k2 * sin(c2 * x)+ k3 * sin(c3 * x)+ k4 * cos(c1 * x)...

问题是使用(k1,k2,k3 ..)的最佳可能值最小化下面所有方程的结果。还知道该问题没有确切的解决方案。所以,
当x是t1时 - > P1-k1 * sin(c1 * t1)-k2 * sin(c2 * t1)-k3 * sin(c3 * t1)-k4 * cos(c1 * t1)...

当x是t2时 - > P2-K1 *罪(C1 * T2)-k2 *罪(C2 * T2)-K3 *罪(C3 * T2)-K4 * COS(C1 * T2)...

当x是t3时 - > P3-k1 * sin(c1 * t3)-k2 * sin(c2 * t3)-k3 * sin(c3 * t3)-k4 * cos(c1 * t3)...

P1是时间变量的绑定值。但是P(t)不是一个解析函数,我只有它们的值,就像什么时候一样 t1 = 5 P1 = 0.7 t2 = 6 P2 = 0.3等。

是否有可能在minizinc或任何其他CP系统中解决这个问题?

1 个答案:

答案 0 :(得分:1)

I don't think that CP is particularly suited to solve this problem, as you don't really have constraints here. All you have are functions you want to minimize (f1,.., fi), and a few degrees of freedom to do so (k1,.., ki).

I feel like the problem is a pretty good candidate for the least squares method. Instead of trying to "fit" your functions f to a given value, you are trying to minimize them. So what you can do is try to fit to 0. (So we would be dealing with non-linear least squares in that care).

Here is what it would like written in Python:

import numpy as np
from scipy.optimize import curve_fit

xdata = np.array([t1, t2, t3, t4, ..., t10])
ydata = np.zeros(10)  # this is your "target". 10 = Number of ti 

def func(x, k1,k2,...ki):
  return (P(x)-k1*sin(c1*x)-k2*sin(c2*x)-k3*sin(c3*x)-k4*cos(c1*x)...)**2  # The square is a trick to minimize the function 

popt, pcov = curve_fit(func, xdata, ydata, k0=(1.0,1.0,...)) # Initial set of ki