0

I have the following set of equations:

x = [x1, x2, x3, x4, x5, x6, x7]
c = [1, 2, 3, 4, 5, 6, 7]
g_cons = [1, 2, 3, 4, 5, 6, 7]
d_cons = [1, 2, 3, 4, 5, 6, 7]
g = Σ(x*g_cons)
d = Σ(x*d_cons)
d_p = d/g*100
e = -0.0038 * d_p * d_p + 0.3501 *d_p – 0.811
ef = (g*(e/100)*365)/55.65
tc = Σ(x*c)

My objective functions are, minimize(ef) and minimize(tc) subj. to Σx <40 and xi bound is [0,15]

I tried the below code, but it throws an error

 super().__init__(n_var=7,
                         n_obj=2,
                         n_constr=1,
                         xl=np.array([0, 0, 0, 0, 0, 0, 0]),
                         xu=np.array([15, 15, 15, 15, 15, 15, 15]))

   def _evaluate(self, x, out, *args, **kwargs):
        c = [1, 2, 3, 4, 5, 6, 7]
        g_cons = [1, 2, 3, 4, 5, 6, 7]
        d_cons = [1, 2, 3, 4, 5, 6, 7]
        f1 = (sum(x*g_cons)*(-0.0038 *(pow(sum(x*g_cons)/sum(x*d_cons)*100,2))+ 
        0.3501*(sum(x*g_cons)/sum(x*d_cons)*100)- 0.811)/100*365)/55.65
        f2 = sum(x*c)

        f1, f2 = f1, f2
        g1 = sum(x)-40

        out["F"] = np.column_stack([f1, f2])
        out["G"] = g1

Error message:

 Exception: Population Set Attribute Error: Number of values and population size do not match!
drisyagv
  • 1
  • 1

1 Answers1

0

notice that the input f the evaluation function, x, shape is (n_pop, n_var) the output of this function, out['f'], must be of shape (n_pop, n_obj). You are currently using sum function in the wrong axis, correct it by using np.sum(array, axis=1) instead as shown below

class PProblem(Problem):
    def __init__(self):
        super().__init__(n_var=7,
                         n_obj=2,
                         n_constr=1,
                         xl=np.array([0, 0, 0, 0, 0, 0, 0]),
                         xu=np.array([15, 15, 15, 15, 15, 15, 15]))

    def _evaluate(self, x, out, *args, **kwargs):
        c = [1, 2, 3, 4, 5, 6, 7]
        g_cons = [1, 2, 3, 4, 5, 6, 7]
        d_cons = [1, 2, 3, 4, 5, 6, 7]
        f1 = (np.sum(x*g_cons,axis=1)*(-0.0038 *(pow(np.sum(x*g_cons,axis=1)/np.sum(x*d_cons,axis=1)*100,2))+ 
        0.3501*(np.sum(x*g_cons,axis=1)/np.sum(x*d_cons,axis=1)*100)- 0.811)/100*365)/55.65
        f2 = np.sum(x*c,axis=1)

        f1, f2 = f1, f2
        g1 = np.sum(x,axis=1)-40
        out["F"] = np.column_stack([f1, f2])
        out["G"] = np.column_stack([g1])

Regards