public static void computeGreedyOpenGoalOrdering(List optimizervariables, int numberofopengoals, List goalsequence, double priorcost, double priorfanout) {
    { Cons goalsequencecheckpoint = null;
      int choicepointunbindingoffset = Stella.NULL_INTEGER;
      Proposition bestgeneratorgoal = null;
      double bestgeneratorfanout = Stella.NULL_FLOAT;
      double bestcombinedcost = Stella.NULL_FLOAT;
      int opengoalreduction = Stella.NULL_INTEGER;

      if (optimizervariables.emptyP()) {
        KeyValueList.setDynamicSlotValue(((QueryIterator)(Logic.$QUERYITERATOR$.get())).dynamicSlots, Logic.SYM_LOGIC_BEST_GOAL_SEQUENCE, goalsequence, null);
        return;
      }
      for (;;) {
        bestgeneratorgoal = null;
        bestgeneratorfanout = Stella.NULL_FLOAT;
        bestcombinedcost = Stella.NULL_FLOAT;
        { PatternVariable vbl = null;
          Cons iter000 = optimizervariables.theConsList;

          loop001 : for (;!(iter000 == Stella.NIL); iter000 = iter000.rest) {
            vbl = ((PatternVariable)(iter000.value));
            if (!PatternVariable.variableBoundP(vbl)) {
              { Proposition generatorgoal = null;
                double generatorcost = Stella.NULL_FLOAT;
                double generatorfanout = Stella.NULL_FLOAT;

                { Object [] caller_MV_returnarray = new Object[2];

                  generatorgoal = PatternVariable.cheapestGeneratorGoal(vbl, caller_MV_returnarray);
                  generatorcost = ((double)(((FloatWrapper)(caller_MV_returnarray[0])).wrapperValue));
                  generatorfanout = ((double)(((FloatWrapper)(caller_MV_returnarray[1])).wrapperValue));
                }
                if (generatorgoal == null) {
                  continue loop001;
                }
                goalsequencecheckpoint = goalsequence.theConsList;
                choicepointunbindingoffset = Logic.simulateCreateChoicePoint();
                goalsequence.push(generatorgoal);
                Proposition.bindAllVariablesInGeneratorGoal(generatorgoal, goalsequence);
                opengoalreduction = Native.ceiling((((double)(goalsequence.length() - goalsequencecheckpoint.length())) / numberofopengoals) * 100);
                { double combinedcost = (generatorfanout + generatorcost) - opengoalreduction;

                  if ((bestcombinedcost == Stella.NULL_FLOAT) ||
                      (combinedcost < bestcombinedcost)) {
                    bestgeneratorgoal = generatorgoal;
                    bestgeneratorfanout = generatorfanout;
                    bestcombinedcost = combinedcost;
                  }
                }
                goalsequence.theConsList = goalsequencecheckpoint;
                PatternRecord.unbindVariablesBeginningAt(((QueryIterator)(Logic.$QUERYITERATOR$.get())).currentPatternRecord, choicepointunbindingoffset);
              }
            }
          }
        }
        if (bestgeneratorgoal == null) {
          if (goalsequence.length() == numberofopengoals) {
            KeyValueList.setDynamicSlotValue(((QueryIterator)(Logic.$QUERYITERATOR$.get())).dynamicSlots, Logic.SYM_LOGIC_BEST_COST, FloatWrapper.wrapFloat(priorcost), Stella.NULL_FLOAT_WRAPPER);
            KeyValueList.setDynamicSlotValue(((QueryIterator)(Logic.$QUERYITERATOR$.get())).dynamicSlots, Logic.SYM_LOGIC_BEST_GOAL_SEQUENCE, goalsequence, null);
          }
          return;
        }
        priorfanout = priorfanout * bestgeneratorfanout;
        goalsequence.push(bestgeneratorgoal);
        Proposition.bindAllVariablesInGeneratorGoal(bestgeneratorgoal, goalsequence);
      }
    }
  }