Package cn.edu.zju.acm.onlinejudge.bean

Examples of cn.edu.zju.acm.onlinejudge.bean.Problem


    private void judge(Submission submission) throws JudgeServerErrorException,
            IOException,
            PersistenceException,
            JudgeClientErrorException,
            ProblemDataErrorException {
        Problem problem = this.problemDAO.getProblem(submission.getProblemId());
        int reply = this.sendJudgeCommand(problem.getId(), problem.getRevision(), submission.getId());
        if (reply == JudgeReply.NO_SUCH_PROBLEM.getId()) {
            reply = this.sendDataCommand(problem);
        }
        if (reply == JudgeReply.COMPILATION_ERROR.getId()) {
            int length = this.in.readInt();
            byte[] bytes = new byte[length];
            this.in.read(bytes);
            throw new ProblemDataErrorException("Special judge compilation failure for problem " + problem.getId() + ": " + new String(bytes));
        }
        if (reply != JudgeReply.READY.getId()) {
            throw new JudgeClientErrorException();
        }
        String content = submission.getContent();
        if (content == null) {
            content = this.submissionDAO.getSubmissionSource(submission.getId());
        }
        reply = this.sendCompileCommand(submission.getId(), submission.getLanguage(), content);
        if (reply != JudgeReply.COMPILING.getId()) {
            throw new JudgeClientErrorException();
        }
        submission.setJudgeReply(JudgeReply.COMPILING);
        reply = this.readJudgeReply();

        if (reply == JudgeReply.COMPILATION_ERROR.getId()) {
            submission.setJudgeReply(JudgeReply.COMPILATION_ERROR);
            int length = this.in.readInt();
            byte[] bytes = new byte[length];
            this.in.read(bytes);
            submission.setJudgeComment(new String(bytes));
            return;
        } else if (reply != JudgeReply.READY.getId()) {
            throw new JudgeClientErrorException();
        }
        Limit limit = problem.getLimit();
        reply = this.sendTestcaseCommand(1, limit.getTimeLimit(), limit.getMemoryLimit(), limit.getOutputLimit());
        submission.setJudgeReply(JudgeReply.RUNNING);
        submission.setTimeConsumption(0);
        submission.setMemoryConsumption(0);
        while (reply == JudgeReply.RUNNING.getId()) {
View Full Code Here


        if (forward != null) {
            return forward;
        }

        AbstractContest contest = context.getContest();
        Problem problem = context.getProblem();

        long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
        Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
        if (language == null) {
            return this.handleSuccess(mapping, context, "submit");
        }
        String source = context.getRequest().getParameter("source");
        if (source == null || source.length() == 0) {
            return this.handleSuccess(mapping, context, "submit");
        }
       
        List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
        if(refrance.size()!=0) {
          Reference r = (Reference)refrance.get(0);
          String percode = new String(r.getContent());
          source=percode+"\n"+source;
        }
       
        UserProfile user = context.getUserProfile();
        if (submitCache != null && submitCache.contains(user.getId())) {
          
          ActionMessages messages = new ActionMessages();      
            messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
            this.saveErrors(context.getRequest(), messages);
           
            context.setAttribute("source", source);
           
          return handleSuccess(mapping, context, "submit");
        }
       
        if (contest.isCheckIp()) {
            forward = this.checkLastLoginIP(mapping, context, isProblemset);
            if (forward != null) {
                return forward;
            }
        }
        Submission submission = new Submission();
        submission.setContestId(contest.getId());
        submission.setLanguage(language);
        submission.setProblemId(problem.getId());
        submission.setUserProfileId(user.getId());
        submission.setContent(source);
        submission.setMemoryConsumption(0);
        submission.setTimeConsumption(0);
        submission.setSubmitDate(new Date());
        SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();

        if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
            submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
            submissionPersistence.createSubmission(submission, user.getId());
        } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
            submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
            submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
            submissionPersistence.createSubmission(submission, user.getId());
        } else {
            submission.setJudgeReply(JudgeReply.QUEUING);
            submissionPersistence.createSubmission(submission, user.getId());
View Full Code Here

    }

    public Problem getProblem(long problemId) throws PersistenceException {
        Object key = new Long(problemId);
        synchronized (this.problemCache) {
            Problem problem = this.problemCache.get(key);
            if (problem == null) {
                ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
                problem = problemPersistence.getProblem(problemId);
                this.problemCache.put(key, problem);
            }
View Full Code Here

   * @param limit the limit
   * @param languages  a list of languages
   * @return a new Problem instance
   */
  private Problem newProblem(long id, long contestId, Limit limit) {
    Problem problem = new Problem();
    problem.setId(id);
    problem.setContestId(contestId);
    problem.setCode("code" + id);
    problem.setAuthor("author" + id);
    problem.setChecker(id % 2 == 1);
    problem.setContest("contest" + id);
    problem.setLimit(limit);
    problem.setRevision((int) id * 10);
    problem.setSource("source" + id);
    problem.setTitle("title" + id);   
    return problem;
 
View Full Code Here

        if (forward != null) {
            return forward;
        }

        AbstractContest contest = context.getContest();
        Problem problem = context.getProblem();

        long languageId = Utility.parseLong(context.getRequest().getParameter("languageId"));
        Language language = PersistenceManager.getInstance().getLanguagePersistence().getLanguage(languageId);
        if (language == null) {
            return this.handleSuccess(mapping, context, "submit");
        }
        String source = context.getRequest().getParameter("source");
        if (source == null || source.length() == 0) {
            return this.handleSuccess(mapping, context, "submit");
        }
       
        List refrance = PersistenceManager.getInstance().getReferencePersistence().getProblemReferences(problem.getId(), ReferenceType.HEADER);
        if(refrance.size()!=0) {
          Reference r = (Reference)refrance.get(0);
          String percode = new String(r.getContent());
          source=percode+"\n"+source;
        }
       
        UserProfile user = context.getUserProfile();
        if (submitCache != null && submitCache.contains(user.getId())) {
          
          ActionMessages messages = new ActionMessages();      
            messages.add("message", new ActionMessage("onlinejudge.submit.interval"));
            this.saveErrors(context.getRequest(), messages);
           
            context.setAttribute("source", source);
           
          return handleSuccess(mapping, context, "submit");
        }
       
        if (contest.isCheckIp()) {
            forward = this.checkLastLoginIP(mapping, context, isProblemset);
            if (forward != null) {
                return forward;
            }
        }
        Submission submission = new Submission();
        submission.setContestId(contest.getId());
        submission.setLanguage(language);
        submission.setProblemId(problem.getId());
        submission.setUserProfileId(user.getId());
        submission.setContent(source);
        submission.setMemoryConsumption(0);
        submission.setTimeConsumption(0);
        submission.setSubmitDate(new Date());
        SubmissionPersistence submissionPersistence = PersistenceManager.getInstance().getSubmissionPersistence();

        if (contest.getEndTime() != null && new Date().after(contest.getEndTime())) {
            submission.setJudgeReply(JudgeReply.OUT_OF_CONTEST_TIME);
            submissionPersistence.createSubmission(submission, user.getId());
        } else if (source.getBytes().length > problem.getLimit().getSubmissionLimit() * 1024) {
            submission.setContent(source.substring(0, problem.getLimit().getSubmissionLimit() * 1024));
            submission.setJudgeReply(JudgeReply.SUBMISSION_LIMIT_EXCEEDED);
            submissionPersistence.createSubmission(submission, user.getId());
        } else {
          Random ran=new Random();
            submission.setJudgeReply(ran.nextInt()%2==0 ? JudgeReply.WRONG_ANSWER : JudgeReply.ACCEPTED);
View Full Code Here

        this.score = problem.getScore();

    }

    public Problem toProblem() throws ParseException, NumberFormatException, PersistenceException {
        Problem problem = new Problem();

        if (this.problemId != null) {
            problem.setId(Long.parseLong(this.problemId));
        }
        if (this.contestId != null) {
            problem.setContestId(Long.parseLong(this.contestId));
        }

        problem.setTitle(this.name);
        problem.setCode(this.code);
        problem.setAuthor(this.author);
        problem.setSource(this.source);
        problem.setContest(this.contest);

        Limit limit = new Limit();
        if (!this.useContestDefault) {
            limit.setTimeLimit(Integer.parseInt(this.timeLimit));
            limit.setMemoryLimit(Integer.parseInt(this.memoryLimit));
            limit.setSubmissionLimit(Integer.parseInt(this.submissionLimit));
            limit.setOutputLimit(Integer.parseInt(this.outputLimit));
        }
        problem.setLimit(limit);
        problem.setChecker(this.specialJudge);

        problem.setColor(this.color);
        problem.setScore(this.score);
        return problem;
    }
View Full Code Here

        }
        return this.solved.contains(p);
    }

    public boolean isSolved(long id) {
        Problem p = new Problem();
        p.setId(id);
        return this.isSolved(p);
    }
View Full Code Here

            return forward;
        }

        ProblemForm problemForm = (ProblemForm) form;
        if (problemForm == null || problemForm.getName() == null) {
            Problem problem = context.getProblem();
            problemForm.populate(problem, context.getContest());
            this.setReference("DescriptionRef", ReferenceType.DESCRIPTION, problem.getId(), context);
            this.setReference("InputRef", ReferenceType.INPUT, problem.getId(), context);
            this.setReference("OutputRef", ReferenceType.OUTPUT, problem.getId(), context);
            this.setReference("JudgeSolutionRef", ReferenceType.JUDGE_SOLUTION, problem.getId(), context);
            this.setReference("HeaderRef", ReferenceType.HEADER, problem.getId(), context);
            this.setReference("CheckerSourceRef", ReferenceType.CHECKER_SOURCE, problem.getId(), context);
            return this.handleSuccess(mapping, context, "failure");
        }

        // check title and code
        ActionMessages errors = this.validate(problemForm, context);
        if (errors.size() > 0) {
            return this.handleFailure(mapping, context, errors);
        }

        ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
        AbstractContest contest = context.getContest();

        Problem problem = problemForm.toProblem();
        if (problemForm.isUseContestDefault()) {
            problem.getLimit().setId(contest.getLimit().getId());
        }

        long userId = context.getUserSecurity().getId();
        // create problem
        problemPersistence.updateProblem(problem, userId);

        // cprete problem reference, i.e. text, input, output, checker, judge solution, checker source
        this.updateReference(ReferenceType.DESCRIPTION, problemForm.getDescription(), problem.getId(), userId);
        this.updateReference(ReferenceType.INPUT, problemForm.getInputData(), problem.getId(), userId);
        this.updateReference(ReferenceType.OUTPUT, problemForm.getOutputData(), problem.getId(), userId);
        this.updateReference(ReferenceType.HEADER, problemForm.getChecker(), problem.getId(), userId);
        this.updateReference(ReferenceType.CHECKER_SOURCE, problemForm.getCheckerSource(), problem.getId(), userId);
        this.updateReference(ReferenceType.JUDGE_SOLUTION, problemForm.getJudgeSolution(), problem.getId(), userId);

        ContestManager.getInstance().refreshProblem(problem);

        return this.handleSuccess(mapping, context, "success", "?contestId=" + contest.getId());
    }
View Full Code Here

                errors.add("name", new ActionMessage("ProblemForm.name.used"));
                break;
            }
        }*/
        for (Object obj : problems) {
            Problem p = (Problem) obj;
            if (!form.getProblemId().equals("" + p.getId()) && p.getCode().equals(code)) {
                errors.add("code", new ActionMessage("ProblemForm.code.used"));
                break;
            }
        }
        return errors;
View Full Code Here

    public static void init() throws Exception {
        ReflectionUtil.setFieldValue(DAOFactory.class, "languageDAO", new MockLanguageDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "problemDAO", new MockProblemDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "submissionDAO", new MockSubmissionDAO());
        ReflectionUtil.setFieldValue(DAOFactory.class, "referenceDAO", new MockReferenceDAO());
        Problem problem = new Problem();
        problem.setId(0);
        problem.setRevision(0);
        Limit limit = new Limit();
        limit.setTimeLimit(1);
        limit.setMemoryLimit(1024);
        limit.setOutputLimit(1);
        problem.setLimit(limit);
        Reference reference = new Reference();
        reference.setReferenceType(ReferenceType.INPUT);
        reference.setContent("0 0\n1 2\n2 3\n".getBytes("ASCII"));
        DAOFactory.getReferenceDAO().save(reference, 0);
        DAOFactory.getReferenceDAO().save(reference, 1);
View Full Code Here

TOP

Related Classes of cn.edu.zju.acm.onlinejudge.bean.Problem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.