ses_flow_jr()
authoryu.dongliang <18588496441@163.com>
Fri, 15 Sep 2023 08:43:22 +0000 (16:43 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 15 Sep 2023 08:43:22 +0000 (16:43 +0800)
ses_core.h
ses_step_va_balance.c
ses_steps.c

index 35a095be125544115917053342624392f9be8f19..03311275359e56b42496b0f25e92d5531894a0c2 100644 (file)
@@ -24,13 +24,13 @@ struct ses_flow_s
 {
        scf_vector_t*  paths;
 
-       scf_vector_t*  ppins;
-       scf_vector_t*  npins;
-
        ScfEpin*       vip;
 
-       double         r;
-       double         jr;
+       double         pr;
+       double         jpr;
+
+       double         nr;
+       double         jnr;
 
        double         v;
        double         jv;
@@ -87,6 +87,7 @@ void        ses_path_print(ses_path_t* path);
 ses_flow_t* ses_flow_alloc();
 void        ses_flow_free (ses_flow_t* flow);
 void        ses_flow_print(ses_flow_t* flow);
+void        ses_flow_jr   (ses_flow_t* flow);
 
 ses_ctx_t*  ses_ctx_alloc();
 void        ses_ctx_free (ses_ctx_t* ctx);
index 208ecd1cef590a1a8e3f5cb53a1e44a967376380..fe04f783084a3893d6945e5c2813be300dced21f 100644 (file)
@@ -169,11 +169,16 @@ static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_c
                ses_flow_print(flow0);
                printf("\n");
 
+               ses_flow_jr(flow0);
+
                printf("-------------\n");
 
                ses_flow_print(flow1);
                printf("\n");
 
+               ses_flow_jr(flow1);
+               printf("-------------\n");
+
                ret = __ses_path_va_balance(f, bridge, flow0, flow1);
                if (ret < 0)
                        return ret;
index 9867497643b14a4682c936a52e48f4e0c101e1aa..3ed7fcc027f2153457146f95ce33ad1606055c72 100644 (file)
@@ -52,26 +52,12 @@ ses_flow_t* ses_flow_alloc()
                return NULL;
 
        flow->paths = scf_vector_alloc();
-       if (!flow->paths)
-               goto _paths_error;
-
-       flow->ppins = scf_vector_alloc();
-       if (!flow->ppins)
-               goto _ppins_error;
-
-       flow->npins = scf_vector_alloc();
-       if (!flow->npins)
-               goto _npins_error;
+       if (!flow->paths) {
+               ses_flow_free(flow);
+               return NULL;
+       }
 
        return flow;
-
-_npins_error:
-       scf_vector_free(flow->ppins);
-_ppins_error:
-       scf_vector_free(flow->paths);
-_paths_error:
-       free(flow);
-       return NULL;
 }
 
 void ses_flow_free(ses_flow_t* flow)
@@ -80,13 +66,71 @@ void ses_flow_free(ses_flow_t* flow)
                if (flow->paths)
                        scf_vector_free(flow->paths);
 
-               if (flow->ppins)
-                       scf_vector_free(flow->ppins);
+               free(flow);
+       }
+}
+
+void ses_flow_jr(ses_flow_t* flow)
+{
+       if (!flow)
+               return;
 
-               if (flow->npins)
-                       scf_vector_free(flow->npins);
+       flow->pr  = 0;
+       flow->jpr = 0;
 
-               free(flow);
+       flow->nr  = 0;
+       flow->jnr = 0;
+
+       if (!flow->paths || !flow->vip)
+               return;
+
+       ses_path_t* path;
+       ScfEpin*    p;
+       ScfEpin*    vip = flow->vip;
+
+       int i;
+       int j;
+
+       for (i   = 0; i < flow->paths->size; i++) {
+               path =        flow->paths->data[i];
+
+               for (j = 0; j < path->pins->size; j++) {
+                       p  =        path->pins->data[j];
+
+                       if (p->lid == vip->lid) {
+
+                               vip = path->pins->data[0];
+
+                               flow->pr  += p->pr;
+                               flow->jpr += p->jpr;
+
+                               scf_loge("flow->pr: %lg + j%lg, c%ldp%ld->pr: %lg + j%lg, vip c%ldp%ld->pr: %lg + j%lg\n",
+                                               flow->pr, flow->jpr, p->cid, p->id, p->pr, p->jpr, vip->cid, vip->id, vip->pr, vip->jpr);
+                               break;
+                       }
+               }
+       }
+
+       vip = flow->vip;
+
+       for (i   = 0; i < flow->paths->size; i++) {
+               path =        flow->paths->data[i];
+
+               for (j = 0; j < path->pins->size; j++) {
+                       p  =        path->pins->data[j];
+
+                       if (p->lid == vip->lid) {
+
+                               vip = path->pins->data[path->pins->size - 1];
+
+                               flow->nr  += vip->pr  - p->pr;
+                               flow->jnr += vip->jpr - p->jpr;
+
+                               scf_loge("flow->nr: %lg + j%lg, c%ldp%ld->pr: %lg + j%lg, vip c%ldp%ld->pr: %lg + j%lg\n",
+                                               flow->nr, flow->jnr, p->cid, p->id, p->pr, p->jpr, vip->cid, vip->id, vip->pr, vip->jpr);
+                               break;
+                       }
+               }
        }
 }