Flow/Job Shop to Boolean satisfiability [Polynomial-time reduction] part 2

徘徊边缘 提交于 2020-01-15 12:37:36

问题


here is the continuity of my first question (Flow Shop to Boolean satisfiability [Polynomial-time reduction]).

Because something is wrong and I didn't success to know where exactly. I ask for the help of StackOverFlow's masters once again :)

For the sum-up of what I have for now :

  • I have input file who look like this :
3 2
1 1 1
1 1 1

Who represents : 3 jobs, 2 shops (machines), and the duration of each job on each shop (machine). And I want for theses problems, to find the optimum C_max value.

So for example, it should give in output this result (sorry for paint.exe xD):

So to read theses files, I create 2 structures : Resource and Problem who look like this :

typedef struct _resource {

   unsigned int numShop;
   unsigned int numJob;
   unsigned int value;

} Resource;

typedef struct _problem {

   unsigned int nbShops;
   unsigned int nbJobs;
   Resource** resources;

} Problem;

The reading is okay, and I have all the informations in the input files inside my structures.

I want to transform this optimal problem (find the best solution) into a decision problem (is THIS a possible solution ?) and for this, my goal is to transform the JobShop/FlowShop problem into a SAT problem.

  • My goal is as follow : I put the value of C_max as fixed, I create a SAT problem, and I will decrease the C_max until the SAT-solver says that the problem has no solution. The last-value with a solution will be the optimal value.

Thanks to @Jens Schauder, I have the beginning of a solution. My booleans variables are like this: s_1_2_3 with the meaning resource one gets used at machine 2 starting from time 3.

So if I have J jobs, M shops and I put my C_max to the value C, I will have for sure : J * M * C booleans variables.

Problem: for now my SAT problem are wrong. The solution given is not okay.

Here are the constraints that I have for now : ( V means 'OR', the other : 'And')

Which means that the job i can be on only 1 shop for a time k

Which means that a shop j can handle only 1 job for a time k.

Which means that if the job has a duration more than 1, it has to be contineous. So if one variable is true, the other after until the end of duration of the task have to be true also.

I'm not really sure if I'm right about the formulation of the problem, or/and if I forgot a constraint.

For now, I mind also Job Shop (Flow Shop is basically the same where the jobs have to be in the same order on every shops)

Sorry for the very big question, but for this kind of problem, it's better to have all the details to know what is it about.


EDIT

I will add the source code of the 3 contraints above, maybe something is wrong inside and I don't see what...

Constraint n°1 :

/** the job i can be on only 1 shop for a time k */
unsigned int writeConstraintOne(Problem* problem, unsigned int timeMax, FILE* file, char forReal) {

unsigned int final = 0;
unsigned int max = getNbVariables(problem,timeMax);

for(unsigned int i = 0; i < problem->nbShops; i++) {

  for(unsigned int l = 0; l < problem->nbShops; l++) {

    for(unsigned int j = 0; j < problem->nbJobs; j++) {

     for(unsigned int t = 0; t < timeMax; t++) {

      if(i == l) continue;

      /** We get the S_i_j_t */
      unsigned int A = getIdOfVariable(problem,i,j,t,timeMax);

      /** We get the S_l_j_t */
      unsigned int B = getIdOfVariable(problem,l,j,t,timeMax);

      final++;

      /* This fonction will or count the number of clauses, 
       * or write them inside the file. */
      if(forReal == 1) {

          /* It represents -A => B */
          fprintf(file,"-%d -%d 0\n",A,B);
      }
       }
      }
    }
   }
   return final;
 }

Constraint n°2 :

/** shop j can handle only 1 job for a time k. */
unsigned int writeConstraintTwo(Problem* problem, unsigned int timeMax, FILE* file, char forReal) {

unsigned int final = 0;
unsigned int max = getNbVariables(problem,timeMax);

for(unsigned int i = 0; i < problem->nbShops; i++) {

  for(unsigned int l = 0; l < problem->nbJobs; l++) {

    for(unsigned int j = 0; j < problem->nbJobs; j++) {

     for(unsigned int t = 0; t < timeMax; t++) {

      if(j == l) continue;

      /** We get the S_i_j_t */
      unsigned int A = getIdOfVariable(problem,i,j,t,timeMax);

      /** We get the S_i_l_t */
      unsigned int B = getIdOfVariable(problem,i,l,t,timeMax);

      final++;

      /* This fonction will or count the number of clauses, 
       * or write them inside the file. */
      if(forReal == 1) {

          /* It represents -A => B */
          fprintf(file,"-%d -%d 0\n",A,B);
      }
       }
      }
    }
   }
   return final;
 }

Constraint n°3 :

/** if the job has a duration more than 1, it has to be contineous. 
 *  So if one variable is true, the other after until the end of duration 
 *  of the task have to be true also. */
unsigned int writeConstraintThree(Problem* problem, unsigned int timeMax, FILE* file, char forReal) {

unsigned int final = 0;
unsigned int max = getNbVariables(problem,timeMax);

for(unsigned int i = 0; i < problem->nbShops; i++) {

    for(unsigned int j = 0; j < problem->nbJobs; j++) {

     for(unsigned int t = 0; t < timeMax; t++) {

     for(unsigned int k = 0; k < problem->resource[i][j].value-1; k++) {

      if(k == t) continue;

      /** We get the S_i_j_t */
      unsigned int A = getIdOfVariable(problem,i,j,t,timeMax);

      /** We get the S_i_j_k */
      unsigned int B = getIdOfVariable(problem,i,j,k,timeMax);

      final+= 2;

      /* This fonction will or count the number of clauses, 
       * or write them inside the file. */
      if(forReal == 1) {

          fprintf(file,"-%d %d 0\n",B,A);
          fprintf(file,"-%d %d 0\n",A,B);
      }
       }
      }
    }
   }
   return final;
 }

回答1:


There is a bug in the first two equation you are giving: you are missing an l != j. Of course I have no idea if this bug is in your code as well.

I think you are also missing a constraint that says: every job has to happen on every machine at least once (you only have the at most once part).

On more hint for debugging this: try it with the simplest examples that are possible: 1 machine, 1 job; and work from there to 2 machines, 1 job and 1 machine 2 jobs.

With 2 machines and three jobs, there is to much that can go wrong.



来源:https://stackoverflow.com/questions/29651856/flow-job-shop-to-boolean-satisfiability-polynomial-time-reduction-part-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!