PuLP: цель Функция: объединить несколько lpSum

Лучший метод генератора случайных строк

public class RandomStringGenerator{

    private static int randomStringLength = 25 ;
    private static boolean allowSpecialCharacters = true ;
    private static String specialCharacters = "!@$%*-_+:";
    private static boolean allowDuplicates = false ;

    private static boolean isAlphanum = false;
    private static boolean isNumeric = false;
    private static boolean isAlpha = false;
    private static final String alphabet = "abcdefghijklmnopqrstuvwxyz";
    private static boolean mixCase = false;
    private static final String capAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String num = "0123456789";

    public static String getRandomString() {
        String returnVal = "";
        int specialCharactersCount = 0;
        int maxspecialCharacters = randomStringLength/4;

        try {
            StringBuffer values = buildList();
            for (int inx = 0; inx < randomStringLength; inx++) {
                int selChar = (int) (Math.random() * (values.length() - 1));
                if (allowSpecialCharacters)
                {
                    if (specialCharacters.indexOf("" + values.charAt(selChar)) > -1)
                    {
                        specialCharactersCount ++;
                        if (specialCharactersCount > maxspecialCharacters)
                        {
                            while (specialCharacters.indexOf("" + values.charAt(selChar)) != -1)
                            {
                                selChar = (int) (Math.random() * (values.length() - 1));
                            }
                        }
                    }
                }
                returnVal += values.charAt(selChar);
                if (!allowDuplicates) {
                    values.deleteCharAt(selChar);
                }
            }
        } catch (Exception e) {
            returnVal = "Error While Processing Values";
        }
        return returnVal;
    }

    private static StringBuffer buildList() {
        StringBuffer list = new StringBuffer(0);
        if (isNumeric || isAlphanum) {
            list.append(num);
        }
        if (isAlpha || isAlphanum) {
            list.append(alphabet);
            if (mixCase) {
                list.append(capAlpha);
            }
        }
        if (allowSpecialCharacters)
        {
            list.append(specialCharacters);
        }
        int currLen = list.length();
        String returnVal = "";
        for (int inx = 0; inx < currLen; inx++) {
            int selChar = (int) (Math.random() * (list.length() - 1));
            returnVal += list.charAt(selChar);
            list.deleteCharAt(selChar);
        }
        list = new StringBuffer(returnVal);
        return list;
    }   

}
0
задан Moritz 16 January 2019 в 13:12
поделиться

1 ответ

Не видя ошибки, я могу быть уверен на 100%, но я думаю, что имя, которое вы включаете в lpsum, вызывает проблему, попробуйте следующее

alloc_prob = pulp.LpProblem("Supplier Allocation Problem", pulp.LpMinimize)

TPC_func = pulp.lpSum(X[s][p]*procCosts[s][p] for s in supplier for p in 
project)
TTC_func = pulp.lpSum(X[s][p]*transCosts[s][p] for s in supplier for p in 
project)
TD_func = pulp.lpSum(X_SEP[c][1]*discountFactor['Bonus / ton [€/t]'][c] for 
c in company)

# Objective function: TPC + TTC - TD -> min
alloc_prob += TPC_func  + TTC_func - TD_func
0
ответ дан Stuart Mitchell 16 January 2019 в 13:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: