liquid_feedback_core

changeset 424:7fbf614ca8cb

Separate configuration options for "defeat_strength" and "tie_breaking"
author jbe
date Mon Apr 14 01:06:42 2014 +0200 (2014-04-14)
parents 73c2ab2d068f
children 514eacf18e36
files core.sql
line diff
     1.1 --- a/core.sql	Thu Apr 10 00:20:03 2014 +0200
     1.2 +++ b/core.sql	Mon Apr 14 01:06:42 2014 +0200
     1.3 @@ -348,9 +348,16 @@
     1.4  COMMENT ON COLUMN "session"."lang"              IS 'Language code of the selected language';
     1.5  
     1.6  
     1.7 -CREATE TYPE "schulze_complexity" AS ENUM ('simple', 'tuple', 'full');
     1.8 -
     1.9 -COMMENT ON TYPE "schulze_complexity" IS 'Variant of Schulze method to use: ''simple'' = only the number of winning votes in a pairwise comparison is considered, ''tuple'' = the number of winning votes (primarily) as well as the number of losing votes (secondarily) are considered, ''full'' = same as ''tuple'' but with additional tie-breaking';
    1.10 +CREATE TYPE "defeat_strength" AS ENUM ('simple', 'tuple');
    1.11 +
    1.12 +COMMENT ON TYPE "defeat_strength" IS 'How pairwise defeats are measured for the Schulze method: ''simple'' = only the number of winning votes, ''tuple'' = primarily the number of winning votes, secondarily the number of losing votes';
    1.13 +
    1.14 +
    1.15 +CREATE TYPE "tie_breaking" AS ENUM ('simple', 'variant1', 'variant2');
    1.16 +
    1.17 +COMMENT ON TYPE "tie_breaking" IS 'Tie-breaker for the Schulze method: ''simple'' = only initiative ids are used, ''variant1'' = use initiative ids in variant 1 for tie breaking of the links (TBRL) and sequentially forbid shared links, ''variant2'' = use initiative ids in variant 2 for tie breaking of the links (TBRL) and sequentially forbid shared links';
    1.18 +
    1.19 +
    1.20  
    1.21  CREATE TABLE "policy" (
    1.22          "id"                    SERIAL4         PRIMARY KEY,
    1.23 @@ -367,7 +374,8 @@
    1.24          "issue_quorum_den"      INT4,
    1.25          "initiative_quorum_num" INT4            NOT NULL,
    1.26          "initiative_quorum_den" INT4            NOT NULL,
    1.27 -        "schulze_complexity"    "schulze_complexity" NOT NULL DEFAULT 'full',
    1.28 +        "defeat_strength"     "defeat_strength" NOT NULL DEFAULT 'tuple',
    1.29 +        "tie_breaking"          "tie_breaking"  NOT NULL DEFAULT 'variant1',
    1.30          "direct_majority_num"           INT4    NOT NULL DEFAULT 1,
    1.31          "direct_majority_den"           INT4    NOT NULL DEFAULT 2,
    1.32          "direct_majority_strict"        BOOLEAN NOT NULL DEFAULT TRUE,
    1.33 @@ -408,7 +416,8 @@
    1.34  COMMENT ON COLUMN "policy"."issue_quorum_den"      IS 'Denominator of potential supporter quorum to be reached by one initiative of an issue to be "accepted" and enter issue state ''discussion''';
    1.35  COMMENT ON COLUMN "policy"."initiative_quorum_num" IS   'Numerator of satisfied supporter quorum  to be reached by an initiative to be "admitted" for voting';
    1.36  COMMENT ON COLUMN "policy"."initiative_quorum_den" IS 'Denominator of satisfied supporter quorum to be reached by an initiative to be "admitted" for voting';
    1.37 -COMMENT ON COLUMN "policy"."schulze_complexity"    IS 'Variant of Schulze method to use; see type "schulze_complexity"';
    1.38 +COMMENT ON COLUMN "policy"."defeat_strength"       IS 'How pairwise defeats are measured for the Schulze method; see type "defeat_strength"';
    1.39 +COMMENT ON COLUMN "policy"."tie_breaking"          IS 'Tie-breaker for the Schulze method; see type "tie_breaking"';
    1.40  COMMENT ON COLUMN "policy"."direct_majority_num"            IS 'Numerator of fraction of neccessary direct majority for initiatives to be attainable as winner';
    1.41  COMMENT ON COLUMN "policy"."direct_majority_den"            IS 'Denominator of fraction of neccessary direct majority for initaitives to be attainable as winner';
    1.42  COMMENT ON COLUMN "policy"."direct_majority_strict"         IS 'If TRUE, then the direct majority must be strictly greater than "direct_majority_num"/"direct_majority_den", otherwise it may also be equal.';
    1.43 @@ -3827,26 +3836,37 @@
    1.44  
    1.45  
    1.46  CREATE FUNCTION "defeat_strength"
    1.47 -  ( "positive_votes_p" INT4, "negative_votes_p" INT4 )
    1.48 +  ( "positive_votes_p"  INT4,
    1.49 +    "negative_votes_p"  INT4,
    1.50 +    "defeat_strength_p" "defeat_strength" )
    1.51    RETURNS INT8
    1.52    LANGUAGE 'plpgsql' IMMUTABLE AS $$
    1.53      BEGIN
    1.54 -      IF "positive_votes_p" > "negative_votes_p" THEN
    1.55 -        RETURN ("positive_votes_p"::INT8 << 31) - "negative_votes_p"::INT8;
    1.56 -      ELSIF "positive_votes_p" = "negative_votes_p" THEN
    1.57 -        RETURN 0;
    1.58 +      IF "defeat_strength_p" = 'simple'::"defeat_strength" THEN
    1.59 +        IF "positive_votes_p" > "negative_votes_p" THEN
    1.60 +          RETURN "positive_votes_p";
    1.61 +        ELSE
    1.62 +          RETURN 0;
    1.63 +        END IF;
    1.64        ELSE
    1.65 -        RETURN -1;
    1.66 +        IF "positive_votes_p" > "negative_votes_p" THEN
    1.67 +          RETURN ("positive_votes_p"::INT8 << 31) - "negative_votes_p"::INT8;
    1.68 +        ELSIF "positive_votes_p" = "negative_votes_p" THEN
    1.69 +          RETURN 0;
    1.70 +        ELSE
    1.71 +          RETURN -1;
    1.72 +        END IF;
    1.73        END IF;
    1.74      END;
    1.75    $$;
    1.76  
    1.77 -COMMENT ON FUNCTION "defeat_strength"(INT4, INT4) IS 'Calculates defeat strength (INT8!) of a pairwise defeat primarily by the absolute number of votes for the winner and secondarily by the absolute number of votes for the loser';
    1.78 +COMMENT ON FUNCTION "defeat_strength"(INT4, INT4, "defeat_strength") IS 'Calculates defeat strength (INT8!) of a pairwise defeat primarily by the absolute number of votes for the winner and secondarily by the absolute number of votes for the loser';
    1.79  
    1.80  
    1.81  CREATE FUNCTION "secondary_link_strength"
    1.82    ( "initiative_id1_p" "initiative"."id"%TYPE,
    1.83 -    "initiative_id2_p" "initiative"."id"%TYPE )
    1.84 +    "initiative_id2_p" "initiative"."id"%TYPE,
    1.85 +    "tie_breaking_p"   "tie_breaking" )
    1.86    RETURNS INT8
    1.87    LANGUAGE 'plpgsql' IMMUTABLE AS $$
    1.88      BEGIN
    1.89 @@ -3857,13 +3877,17 @@
    1.90          CASE WHEN "initiative_id1_p" < "initiative_id2_p" THEN
    1.91            1::INT8 << 62
    1.92          ELSE 0 END
    1.93 -        - ("initiative_id1_p"::INT8 << 31)
    1.94 -        + "initiative_id2_p"::INT8
    1.95 +        +
    1.96 +        CASE WHEN "tie_breaking_p" = 'variant2'::"tie_breaking" THEN
    1.97 +          ("initiative_id2_p"::INT8 << 31) - "initiative_id1_p"::INT8
    1.98 +        ELSE
    1.99 +          "initiative_id2_p"::INT8 - ("initiative_id1_p"::INT8 << 31)
   1.100 +        END
   1.101        );
   1.102      END;
   1.103    $$;
   1.104  
   1.105 -COMMENT ON FUNCTION "secondary_link_strength"(INT4, INT4) IS 'Calculates a secondary criterion for the defeat strength (tie-breaking of the links)';
   1.106 +COMMENT ON FUNCTION "secondary_link_strength"(INT4, INT4, "tie_breaking") IS 'Calculates a secondary criterion for the defeat strength (tie-breaking of the links)';
   1.107  
   1.108  
   1.109  CREATE FUNCTION "calculate_ranks"("issue_id_p" "issue"."id"%TYPE)
   1.110 @@ -3925,7 +3949,8 @@
   1.111            IF "i" != "j" THEN
   1.112              "matrix"["i"]["j"] := "defeat_strength"(
   1.113                "vote_matrix"["i"]["j"],
   1.114 -              "vote_matrix"["j"]["i"]
   1.115 +              "vote_matrix"["j"]["i"],
   1.116 +              "policy_row"."defeat_strength"
   1.117              );
   1.118            END IF;
   1.119            EXIT WHEN "j" = "dimension_v";

Impressum / About Us